Skip to content

Commit 50f5707

Browse files
StefanStojanovicRafaelGSS
authored andcommitted
src: fix kill signal 0 on Windows
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923 Fixes: #57669 PR-URL: #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>
1 parent 21f3c96 commit 50f5707

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/process_wrap.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class ProcessWrap : public HandleWrap {
385385
}
386386
#ifdef _WIN32
387387
if (signal != SIGKILL && signal != SIGTERM && signal != SIGINT &&
388-
signal != SIGQUIT) {
388+
signal != SIGQUIT && signal != 0) {
389389
signal = SIGKILL;
390390
}
391391
#endif

test/parallel/test-child-process-kill.js

+20
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,23 @@ if (common.isWindows) {
5858
});
5959
process.kill('SIGHUP');
6060
}
61+
62+
// Test that the process is not killed when sending a 0 signal.
63+
// This is a no-op signal that is used to check if the process is alive.
64+
const code = `const interval = setInterval(() => {}, 1000);
65+
process.stdin.on('data', () => { clearInterval(interval); });
66+
process.stdout.write('x');`;
67+
68+
const checkProcess = spawn(process.execPath, ['-e', code]);
69+
70+
checkProcess.on('exit', (code, signal) => {
71+
assert.strictEqual(code, 0);
72+
assert.strictEqual(signal, null);
73+
});
74+
75+
checkProcess.stdout.on('data', common.mustCall((chunk) => {
76+
assert.strictEqual(chunk.toString(), 'x');
77+
checkProcess.kill(0);
78+
checkProcess.stdin.write('x');
79+
checkProcess.stdin.end();
80+
}));

0 commit comments

Comments
 (0)