Skip to content

src: fix kill signal 0 on Windows - #57695

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
JaneaSystems:mefi-kill-fix
Apr 4, 2025
Merged

src: fix kill signal 0 on Windows#57695
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
JaneaSystems:mefi-kill-fix

Conversation

@StefanStojanovic

Copy link
Copy Markdown
Contributor

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

@StefanStojanovicStefanStojanovic added windows Issues and PRs related to the Windows platform. process Issues and PRs related to the process subsystem. labels Mar 31, 2025
@nodejs-github-botnodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Mar 31, 2025
@codecov

codecovBot commented Mar 31, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.24%. Comparing base (657f818) to head (cd81beb).
Report is 538 commits behind head on main.

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 
Files with missing linesCoverage Δ
src/process_wrap.cc66.66% <ø> (ø)

... and 27 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@targos

Copy link
Copy Markdown
Member

Is it possible to add a test?

@StefanStojanovic

Copy link
Copy Markdown
ContributorAuthor

Is it possible to add a test?

Good idea. I've added it. Hopefully, the 1 second I gave it will be enough for the CI machines.

Comment on lines 66 to 71

@lpincalpincaApr 1, 2025

Copy link
Copy Markdown
Member

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.

Suggested change
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');

Copy link
Copy Markdown
ContributorAuthor

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?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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:

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?

Copy link
Copy Markdown
ContributorAuthor

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
ContributorAuthor

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.

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 1, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 1, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

This special case was missed in the previous changes to this file.
Refs: nodejs#55514
Refs: nodejs#42923Fixes: nodejs#57669
@StefanStojanovicStefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 3, 2025
@github-actionsgithub-actionsBot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Apr 3, 2025
@github-actions

Copy link
Copy Markdown
Contributor
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 PR
https://github.com/nodejs/node/actions/runs/14239782978

@StefanStojanovicStefanStojanovic removed the request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. label Apr 3, 2025
@richardlaurichardlau added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 3, 2025
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 3, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollinamcollina added commit-queue Add this label to land a pull request using GitHub Actions. and removed needs-ci PRs that need a full CI run. labels Apr 4, 2025
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 4, 2025
@nodejs-github-bot
nodejs-github-bot merged commit 32e5e81 into nodejs:mainApr 4, 2025
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 32e5e81

@richardlaurichardlau added lts-watch-v20.x lts-watch-v22.x PRs that may need to be released in v22.x labels Apr 4, 2025
RafaelGSS pushed a commit that referenced this pull request May 1, 2025
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>
RafaelGSS pushed a commit that referenced this pull request May 2, 2025
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>
aduh95 pushed a commit that referenced this pull request May 6, 2025
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>
@aduh95aduh95 removed the lts-watch-v22.x PRs that may need to be released in v22.x label May 6, 2025
RafaelGSS pushed a commit that referenced this pull request May 14, 2025
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>
aduh95 pushed a commit that referenced this pull request May 17, 2025
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>
aduh95 pushed a commit that referenced this pull request May 19, 2025
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>
marco-ippolito pushed a commit that referenced this pull request Jun 5, 2025
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>
@marco-ippolitomarco-ippolito mentioned this pull request Jun 5, 2025
@ghostghost mentioned this pull request Jun 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++Issues and PRs that require attention from people who are familiar with C++.child_processIssues and PRs related to the child_process subsystem.processIssues and PRs related to the process subsystem.windowsIssues and PRs related to the Windows platform.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subprocess.kill(0) terminates the subprocess on Windows since v23.4.0

9 participants

@StefanStojanovic@targos@nodejs-github-bot@mcollina@lpinca@richardlau@jakecastelli@aduh95@marco-ippolito