Description
Version
v23.4.0
Platform
Windows
Subsystem
node:child_process
What steps will reproduce the bug?
import {spawn} from 'node:child_process';
const subprocess = spawn('node', ['--version']);
subprocess.kill(0);
subprocess.on('exit', (exitCode, signalCode) => {
console.log({exitCode, signalCode});
});
How often does it reproduce? Is there a required condition?
Windows-only. Since Node 23.4.0.
What is the expected behavior? Why is that the expected behavior?
Before Node 23.4.0, the subprocess is not terminated on any platform.
{ exitCode: 0, signalCode: null }
What do you see instead?
Since Node 23.4.0, the subprocess is terminated immediately on Windows:
{ exitCode: null, signalCode: 'SIGKILL' }
On non-Windows platforms, the behavior has not changed.
Additional information
This was introduced by the following PR: #55514 and issue: #42923
libuv
handles sending 0
as a special case for Windows, so it works as intended on that platform, and there should not be a reason to convert it to SIGKILL
instead.
0
is described under the following documentation:
0
can be sent to test for the existence of a process, it has no effect if the process exists, but will throw an error if the process does not exist.
Windows does not support signals so has no equivalent to termination by signal, but Node.js offers some emulation withprocess.kill()
, andsubprocess.kill()
:
Sending signal0
can be used as a platform independent way to test for the existence of a process.
It seems like this PR forgot that special case.
node/lib/internal/child_process.js
Lines 493 to 499 in ca74d64