Node.JS ChildProcess.on('exit') does not get hit when spawned process exits

Viewed 40

I have an executable written in C++ that runs calculations on a data file. Depending on the contents, these calculations can take from seconds to more than half an hour. I have an Electron application launching this executable and waiting for it to finish. My code is in the rendering process and it looks something like:

this.exec = spawn(exeLocation, ['run', '-f', 'input file.dat']);

this.exec.stdout.on('data', doSomethingWithOutputData);
this.exec.stderr.on('data', doSomethingWithErrorData);

this.exec.on('exit', (code) => {
  console.log(`exit with code ${code}`);
  markExecTerminated();
});

this.exec.on('close', (code) => {
  console.log(`close with code ${code}`);
  markExecTerminated();
});

The problem I have is that the callbacks for exit and close get hit when the executable takes a few seconds or a few minutes, but when it takes over half an hour, the same callbacks never get called.

(Please note that originally I was handling only the close event. I added the exit event handler just to see if it would get called.)

I am completely stumped by this behavior. I would have expected consistent failure or success, but not something driven by how long it takes for the external exe to run.

I am looking for suggestions on why this is happening and/or how I can consistently get notified when the external exe finishes.

0 Answers
Related