Uh oh!
There was an error while loading. Please reload this page.
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:
|
targos
commented
Mar 31, 2025
Is it possible to add a test? |
b84c0d0 to
d33c9e9CompareStefanStojanovic
commented
Mar 31, 2025
Good idea. I've added it. Hopefully, the 1 second I gave it will be enough for the CI machines. |
d33c9e9 to
389bf3fCompareThere was a problem hiding this comment.
Just a suggestion (that can be ignored) to not rely on timers and not wait a second for the test to end.
| constcheckProcess=spawn(process.execPath,['-e','setTimeout(() => {}, 1000)']); | |
| checkProcess.on('exit',(code,signal)=>{ | |
| assert.strictEqual(code,0); | |
| assert.strictEqual(signal,null); | |
| }); | |
| checkProcess.kill(0); | |
| constcheckProcess=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.
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.
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.
Another option can be something like this:
constcode=`const interval = setInterval(() => {}, 1000);process.stdin.on('data', () => { clearInterval(interval); });process.stdout.write('x');`;constcheckProcess=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.
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.
Done, please reapprove when you get a chance. Thanks.
nodejs-github-bot
commented
Apr 1, 2025
This special case was missed in the previous changes to this file. Refs: nodejs#55514 Refs: nodejs#42923Fixes: nodejs#57669
389bf3f to
cd81bebCompareFailed 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 |
nodejs-github-bot
commented
Apr 3, 2025
nodejs-github-bot
commented
Apr 3, 2025
nodejs-github-bot
commented
Apr 3, 2025
nodejs-github-bot
commented
Apr 4, 2025
nodejs-github-bot
commented
Apr 4, 2025
Landed in 32e5e81 |
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
This special case was missed in the previous changes to this file. Refs: #55514 Refs: #42923Fixes: #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>
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