Description
- Subsystem: doc and child_process
According to documentation (https://nodejs.org/dist/latest-v9.x/docs/api/child_process.html#child_process_subprocess_killed) the killed
property has invalid semantic in comparison to ChildProcess::kill method behaviour (internal/child_process.js)
Concretely, the problematic code is
var err = this._handle.kill(signal);
if (err === 0) {
/* Success. */
this.killed = true;
return true;
}
After the this._handle.kill(signal);
method call we have no idea whether the 3-d party process was killed, or it just received a signal, processed it and continues working (it maybe be possible even with such 'kill' signals like SIGINT and SIGTERM).
So I propose to discuss what can be done in this direction to improve expected behaviour.
The easiest solution (and maybe the right one) is to move this.killed = true;
line into _handle.onexit
function and fix to the following code:
if (signalCode) {
this.signalCode = signalCode;
if (this._killWasCalled) { (1)
this.killed = true;
}
} else {
this.exitCode = exitCode;
}
The if block (1) is needed cuz now documentation says '...indicates whether the child process was successfully terminated using subprocess.kill()
'. We can eliminate this block, but we will need to update documentation also.
Strictly speaking, the killed
field isn't very helpful in terms of identifying when process will exit.
We usually use exit
event for that. But, nevertheless, it's strange to see childProcess.killed === true, when in reality process works fine.