-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: fix kill signal 0 on Windows #57695
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57695 +/- ##
=======================================
Coverage 90.23% 90.24%
=======================================
Files 630 630
Lines 185017 185017
Branches 36207 36216 +9
=======================================
+ Hits 166948 166966 +18
- Misses 11020 11025 +5
+ Partials 7049 7026 -23
🚀 New features to boost your workflow:
|
Is it possible to add a test? |
b84c0d0
to
d33c9e9
Compare
Good idea. I've added it. Hopefully, the 1 second I gave it will be enough for the CI machines. |
d33c9e9
to
389bf3f
Compare
const checkProcess = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 1000)']); | ||
checkProcess.on('exit', (code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
}); | ||
checkProcess.kill(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion (that can be ignored) to not rely on timers and not wait a second for the test to end.
const checkProcess = spawn(process.execPath, ['-e', 'setTimeout(() => {}, 1000)']); | |
checkProcess.on('exit', (code, signal) => { | |
assert.strictEqual(code, 0); | |
assert.strictEqual(signal, null); | |
}); | |
checkProcess.kill(0); | |
const checkProcess = spawn(process.execPath, [ | |
'-e', | |
'setInterval(() => {}, 1000)' | |
]); | |
checkProcess.on('exit', (code, signal) => { | |
assert.strictEqual(code, null); | |
assert.strictEqual(signal, 'SIGTERM'); | |
}); | |
checkProcess.kill(0); // 'SIGKILL' is not sent to the child process. | |
checkProcess.kill('SIGTERM'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like changing timeout to interval and then killing it manually to have complete control. However, the new asserts change the nature of the test itself. We want to test checkProcess.kill(0);
and see if the code and signal will be as expected. This change checks if sending 0
will kill the process, but not if it'll return the expected values. Correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct, the assumption is that checkProcess.kill(0)
is a no-op because the received signal is 'SIGTERM'
. If it wasn't the received signal would be 'SIGKILL'
. I think this is sufficient to assert that it doesn't change the signal. However, as you said, there is no check on the exit code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option can be something like this:
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();
}));
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that one. It's more elegant IMHO. You can submit it as a new suggestion if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to apply it yourself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please reapprove when you get a chance. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This special case was missed in the previous changes to this file. Refs: nodejs#55514 Refs: nodejs#42923 Fixes: nodejs#57669
389bf3f
to
cd81beb
Compare
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - src: fix kill signal 0 on Windows ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/14239782978 |
Landed in 32e5e81 |
The previous changes to this file missed the special case of
process.kill(0)
, thus breaking it on Windows. This PR fixes that.Refs: #55514
Refs: #42923
Fixes: #57669