Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
child_process: support numeric signal argument to kill.#9651
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
gerrard00 commented Nov 17, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
addaleax commented Nov 17, 2016
Awesome! Do you think you could get a test for this together? There’s a bit on that in https://github.com/nodejs/node/blob/master/doc/guides/writing_tests.md, but I’d assume there are existing tests for the string signal names in And a few tiny commit message things: Could you drop the |
gerrard00 commented Nov 17, 2016
Will do! |
ae7c0d4 to 29198d4Compareaddaleax commented Nov 17, 2016
Thanks, apart from the missing tests this looks good! |
29198d4 to 410c589Comparegerrard00 commented Nov 17, 2016
There was an existing test for child-process-kill, so I made a copy of that test and modified it to send the numeric value of SIGTERM. I also modified the commit message as requested. I totally forgot to check that length before pushing. |
lib/internal/child_process.js Outdated
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.
Couldn't this replace the if (sig === 0) check a few lines up?
gerrard00Nov 17, 2016 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
Oh, that makes more sense. Updated.
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.
Please use const instead of var throughout the test.
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.
Could you use common.spawnCat()?
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.
Please add common.mustCall() around the callback, then gotStdoutEOF can be completely removed.
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.
Please use common.fail() here.
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.
Please add common.mustCall() around the callback, then gotStderrEOF can be completely removed.
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.
Please use common.mustCall(), and move the assertions for exitCode and termSignal here.
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.
assert.strictEqual() please.
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.
assert.strictEqual() again here, please.
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.
Once the common.mustCall() changes are made, this can be removed completely.
gerrard00 commented Nov 17, 2016
@cjihrig Those changes are easy enough, but that will make this test very different than the existing child process kill test. Is that ok? |
cjihrig commented Nov 17, 2016
The existing test is outdated, even if it's still technically correct. You can also check out the relatively new https://github.com/nodejs/node/blob/master/doc/guides/writing_tests.md. |
044fdec to 7c08ce9Comparegerrard00 commented Nov 17, 2016
@cjihrig I think I've updated the test correctly. Can you take another look when you have a moment? Thanks for your patience! |
sam-github commented Nov 17, 2016
commit messages should not have a |
gerrard00 commented Nov 17, 2016
@sam-github The period in the commit message was removed based on feedback from @addaleax . |
sam-github left a comment
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.
The commit is missing documentation.
lib/internal/child_process.js Outdated
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.
@cjihrig should we enforce integral, so 1.2 is not acceptable?
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.
@sam-github makes sense to me.
lib/internal/child_process.js Outdated
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.
did you test this? I'm pretty sure that 0 is now going to become 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.
Ouch! That's totally wrong. I didn't test 0 after making the suggested change. Will fix.
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 think this could be constants.os.signals.SIGTERM, so the comment would be unnecessary.
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.
Changed.
sam-github left a comment
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.
this makes child.kill() mysteriously different from process.kill(), doesn't it? They should accept the same arguments.
lib/internal/child_process.js Outdated
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.
This condition has to be after typeof sig === 'number' otherwise signal 0 will be incorrectly converted to 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.
Changed.
sam-github commented Nov 17, 2016
+1 on supporting numeric signals |
sam-github commented Nov 17, 2016
I didn't look around, but if there are existing tests for kill, it would be good to add this to them, it can be hard to find tests when there is one big test file that mostly tests a feature the a couple smaller ones sprinkled about that test the incremental additions that were made over time. ^---- I didn't look around, I'm just at the github review tool right now, if its not the case that there is a good test to extend, and this new test file is the best way, pls ignore. |
9ba3620 to 798fe20Comparegerrard00 commented Nov 17, 2016
@sam-github My lunch break is over, but if I can get the |
addaleax left a comment
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
798fe20 to 5e8cdf9Comparegerrard00 commented Nov 17, 2016
@sam-github I took a cut at updating the docs and fixed a typo in that area. |
doc/api/child_process.md Outdated
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.
String|number -> String|Number
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.
Fixed! That was actually a c+p from process.md, so I'll add another commit to fix that file. Or should I open a different PR for that?
cjihrig commented Nov 18, 2016
The test from this PR could be integrated with |
5e8cdf9 to 7c45e72Comparegerrard00 commented Nov 18, 2016
I'll combine the new test with the existing child process test tomorrow. |
sam-github commented Nov 18, 2016
Btw, I still object to adding numeric signal support to Also, I'm surprised child_process does its own arg checking at all, instead of calling https://github.com/nodejs/node/blob/master/lib/internal/process.js#L152-L178, so that the arg checks, Error strings, etc. would be provably identical. I don't have time to look further, but it looks to me like |
lib/internal/child_process.js Outdated
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.
This should likely check that the value is not an invalid number. For instance:
typeof NaN === 'number' typeof Infinity === 'number' typeof 1.1 === 'number' typeof -1 === 'number' 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.
typeof sig === 'number' && sig >>> 0 === sig should probably do the trick.
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.
Awesome, you just taught me something. I've recently written similar code and used a bunch of || conditions.
Modified as requested.
76e52b8 to 04a8e74Comparegerrard00 commented Nov 21, 2016
@cjihrig I combined the tests as request, can you take a look? @sam-github I'll look into using |
cjihrig left a comment
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 pending CI
04a8e74 to fd7a620CompareFishrock123 commented Dec 16, 2016
@sam-github@targos could you take a look and update your reviews accordingly? |
| @@ -1,4 +1,4 @@ | |||
| # Child Process | |||
| #n Child Process | |||
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.
@gerrard00 You have an extra n here. :)
We can fix that on landing though.
Fishrock123 commented Dec 16, 2016
| The `child.kill()`methods sends a signal to the child process. If no argument | ||
| is given, the process will be sent the `'SIGTERM'` signal. See signal(7) for | ||
| The `child.kill()`method sends a signal to the child process. If no argument | ||
| is given, the process will be sent the `'SIGTERM'` signal. See `signal(7)` for |
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 think we don't put backticks around man page references
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.
is this getting fixed?
| })); | ||
| assert.equal(cat.killed,false); | ||
| cat.kill(); |
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.
Shouldn't it pass sig here?
| } | ||
| runTest(constants.os.signals.SIGTERM); | ||
| runTest('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.
a third test can be added without an argument (to check the default value for signal)
sam-github commented Dec 19, 2016
My comment from #9651 (comment) still stands:
There is no reason to make these two Landing these kind of changes has historically been a source of node API weirdness, wherein two parts of the API subtlely diverge. There is no reason to do that here, lets just make it all better, consistently, at one time. |
Fishrock123 commented Dec 21, 2016
@sam-github Ah, yes. I agree on that. |
Trott commented Mar 19, 2017
@gerrard00 Are you still interested in getting this across the finish line? Adding |
gerrard00 commented Mar 21, 2017
I'll close this and work on a new PR based on the feedback provided. |
thefourtheye commented Mar 21, 2017
Actually #10423 covers implicitly this as well. |
Checklist
make -j8 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
child_process
Description of change
Modifies the kill function to support numeric signals. I used a type check instead of
Number.isIntegerbecause that was the pattern used elsewhere in the code base.Addresses: #9519