From cd81beb2f906ac347b4b8f3d0cc0cc587263ee73 Mon Sep 17 00:00:00 2001 From: StefanStojanovic Date: Mon, 31 Mar 2025 21:48:18 +0200 Subject: [PATCH] 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 --- src/process_wrap.cc | 2 +- test/parallel/test-child-process-kill.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/process_wrap.cc b/src/process_wrap.cc index 6d19c7184c3020..52e3759403b5fa 100644 --- a/src/process_wrap.cc +++ b/src/process_wrap.cc @@ -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 diff --git a/test/parallel/test-child-process-kill.js b/test/parallel/test-child-process-kill.js index 3fa2cac0d455e2..8622153fc6f03b 100644 --- a/test/parallel/test-child-process-kill.js +++ b/test/parallel/test-child-process-kill.js @@ -60,3 +60,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(); +}));