src: fix kill signal 0 on Windows

This special case was missed in the previous changes to this file.

Refs: https://github.com/nodejs/node/pull/55514
Refs: https://github.com/nodejs/node/issues/42923
Fixes: https://github.com/nodejs/node/issues/57669
PR-URL: https://github.com/nodejs/node/pull/57695
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
Stefan Stojanovic 2025-04-04 08:52:52 +02:00 committed by GitHub
parent 870dec25f7
commit 32e5e815ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -385,7 +385,7 @@ class ProcessWrap : public HandleWrap {
}
#ifdef _WIN32
if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT &&
signal != SIGQUIT) {
signal != SIGQUIT && signal != 0) {
signal = SIGKILL;
}
#endif

View File

@ -58,3 +58,23 @@ if (common.isWindows) {
});
process.kill('SIGHUP');
}
// Test that the process is not killed when sending a 0 signal.
// This is a no-op signal that is used to check if the process is alive.
const code = `const interval = setInterval(() => {}, 1000);
process.stdin.on('data', () => { clearInterval(interval); });
process.stdout.write('x');`;
const checkProcess = spawn(process.execPath, ['-e', code]);
checkProcess.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
});
checkProcess.stdout.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk.toString(), 'x');
checkProcess.kill(0);
checkProcess.stdin.write('x');
checkProcess.stdin.end();
}));