Skip to content
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

test: cover thrown errors from exec() kill #11038

Closed
wants to merge 1 commit into from

Conversation

cjihrig
Copy link
Contributor

@cjihrig cjihrig commented Jan 27, 2017

This commit adds code coverage for the scenario where exec() kills a child process, but the call to ChildProcess#kill() throws an exception.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

@nodejs-github-bot nodejs-github-bot added test Issues and PRs related to the tests. lts-watch-v6.x labels Jan 27, 2017
// Keep the process alive and printing to stdout.
setInterval(() => { console.log('foo'); }, 1);
} else {
// Monkey path ChildProcess#kill() to kill the process and then throw.
Copy link
Member

@lpinca lpinca Jan 27, 2017

Choose a reason for hiding this comment

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

s/path/patch/ ?

const cmd = `${process.execPath} ${__filename} child`;
const options = { maxBuffer: 0 };
const child = cp.exec(cmd, options, common.mustCall((err, stdout, stderr) => {
// Verify that if ChildProcess#kill() throws, the error is reported.
Copy link
Contributor

Choose a reason for hiding this comment

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

what if it throws because the child exited, wouldn't that be success?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that I understand the question. Do you mean if Node decides to kill the child process, but in the interim it exits on its own? If exithandler() runs (via the close handler for example), then the error won't be reported because it contains a check to make sure it doesn't run twice.

FWIW, this is the code path being tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

node could decided to kill the child, but between when it decided and the child is killed, the child can exit. It would be possible to special case

ex = e;
for ESRCH, and not call exit handler in that case, because it just means that node has not yet epolled the exit status, but it will in the next tick or so. But the event ordering of the timeout vs the process exit is indeterminate by nature, so its no big deal.

This commit adds code coverage for the scenario where exec()
kills a child process, but the call to ChildProcess#kill()
throws an exception.

PR-URL: nodejs#11038
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@cjihrig
Copy link
Contributor Author

cjihrig commented Jan 30, 2017

@cjihrig
Copy link
Contributor Author

cjihrig commented Feb 10, 2017

CI was 💚

@jasnell
Copy link
Member

jasnell commented Feb 17, 2017

It's been sitting for a bit, new CI: https://ci.nodejs.org/job/node-test-pull-request/6461/

@fhinkel
Copy link
Member

fhinkel commented Mar 26, 2017

Landed in 9ac363b

@fhinkel fhinkel closed this Mar 26, 2017
fhinkel pushed a commit that referenced this pull request Mar 26, 2017
This commit adds code coverage for the scenario where exec()
kills a child process, but the call to ChildProcess#kill()
throws an exception.

PR-URL: #11038
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
@cjihrig cjihrig deleted the coverage branch March 26, 2017 12:04
@cjihrig
Copy link
Contributor Author

cjihrig commented Mar 26, 2017

We'll have to watch this test carefully. I hadn't landed this yet because it appeared to be flakey on Windows.

@gibfahn
Copy link
Member

gibfahn commented Mar 26, 2017

Stress test on Windows: https://ci.nodejs.org/job/node-stress-single-test/1141/

@gibfahn
Copy link
Member

gibfahn commented Mar 26, 2017

Stress test results: OK: 5844 NOT OK: 4155 TOTAL: 9999. This is looping the test sequentially.

@cjihrig should we revert? Mark flaky on windows?

@cjihrig
Copy link
Contributor Author

cjihrig commented Mar 26, 2017

I'd be OK with either. I think there might be a genuine bug with kill() on Windows, so maybe marking it as flaky will keep it on the radar.

gibfahn added a commit to gibfahn/node that referenced this pull request Mar 27, 2017
PR-URL: nodejs#12054
Ref: nodejs#12053
Ref: nodejs#11038
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
This commit adds code coverage for the scenario where exec()
kills a child process, but the call to ChildProcess#kill()
throws an exception.

PR-URL: #11038
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
MylesBorins pushed a commit that referenced this pull request Mar 28, 2017
PR-URL: #12054
Ref: #12053
Ref: #11038
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
@MylesBorins MylesBorins mentioned this pull request Mar 28, 2017
@italoacasas italoacasas mentioned this pull request Apr 10, 2017
2 tasks
@MylesBorins MylesBorins added the baking-for-lts PRs that need to wait before landing in a LTS release. label May 15, 2017
@MylesBorins MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants