Uh oh!
There was an error while loading. Please reload this page.
child_process: support numeric signal argument to kill. - #9651
Conversation
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. |
There was a problem hiding this comment.
Couldn't this replace the if (sig === 0) check a few lines up?
There was a problem hiding this comment.
Oh, that makes more sense. Updated.
There was a problem hiding this comment.
Please use const instead of var throughout the test.
There was a problem hiding this comment.
Could you use common.spawnCat()?
There was a problem hiding this comment.
Please add common.mustCall() around the callback, then gotStdoutEOF can be completely removed.
There was a problem hiding this comment.
Please use common.fail() here.
There was a problem hiding this comment.
Please add common.mustCall() around the callback, then gotStderrEOF can be completely removed.
There was a problem hiding this comment.
Please use common.mustCall(), and move the assertions for exitCode and termSignal here.
There was a problem hiding this comment.
assert.strictEqual() again here, please.
There was a problem hiding this comment.
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.
The commit is missing documentation.
There was a problem hiding this comment.
@cjihrig should we enforce integral, so 1.2 is not acceptable?
There was a problem hiding this comment.
did you test this? I'm pretty sure that 0 is now going to become SIGTERM.
There was a problem hiding this comment.
Ouch! That's totally wrong. I didn't test 0 after making the suggested change. Will fix.
There was a problem hiding this comment.
I think this could be constants.os.signals.SIGTERM, so the comment would be unnecessary.
sam-github
left a comment
There was a problem hiding this comment.
this makes child.kill() mysteriously different from process.kill(), doesn't it? They should accept the same arguments.
There was a problem hiding this comment.
This condition has to be after typeof sig === 'number' otherwise signal 0 will be incorrectly converted to SIGTERM
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 |
798fe20 to
5e8cdf9Comparegerrard00
commented
Nov 17, 2016
@sam-github I took a cut at updating the docs and fixed a typo in that area. |
There was a problem hiding this comment.
String|number -> String|Number
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
typeof sig === 'number' && sig >>> 0 === sig should probably do the trick.
There was a problem hiding this comment.
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 |
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.
@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.
I think we don't put backticks around man page references
| })); | ||
| assert.equal(cat.killed, false); | ||
| cat.kill(); |
| } | ||
| runTest(constants.os.signals.SIGTERM); | ||
| runTest('SIGTERM'); |
There was a problem hiding this comment.
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