GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — workers: fix invalid exit code in parent upon uncaught exception by lundibundi · Pull Request #21713 · nodejs/node

Conversation

@lundibundi

@lundibundi lundibundi commented Jul 8, 2018

Copy link
Copy Markdown
Member

Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.

Fixes: #21707

Checklist
  • make -j4 test (UNIX) passes
  • tests are included
  • commit message follows commit guidelines

Also, if there is any standard shorthand for uncaughtException then please tell me. I'd like to get the message down to 50 columns =).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ciffelia, bricss, and addaleax reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@lundibundi
workers: fix invalid exit code in parent upon uncaught exception
483cdec
Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.

Fixes: nodejs#21707
@nodejs-github-bot nodejs-github-bot added the worker Issues and PRs related to the worker_threads module and Worker API. label Jul 8, 2018
devsnek
devsnek approved these changes Jul 8, 2018
View reviewed changes
hiroppy
hiroppy approved these changes Jul 8, 2018
View reviewed changes
@hiroppy

hiroppy commented Jul 8, 2018

Copy link
Copy Markdown
Member

CI https://ci.nodejs.org/job/node-test-pull-request/15762/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ciffelia
ciffelia reviewed Jul 9, 2018
View reviewed changes
Comment thread lib/internal/worker.js Outdated
function fatalException(error) {
debug(`[${threadId}] gets fatal exception`);

process.exitCode = 1;

@ciffelia ciffelia Jul 9, 2018

Copy link
Copy Markdown

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'm afraid process.exitCode may be 1 even if the exception is caught.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Jul 9, 2018

Copy link
Copy Markdown
Member

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 agree – I think you want to move this into the if (!caught) block below?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ciffelia reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@lundibundi lundibundi Jul 9, 2018

Copy link
Copy Markdown
Member Author

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.

My bad, I assumed that this was unrecoverable (I thought 'uncaughtException' didn't count as recovery). Will push soon. I also added test similar to test-process-exit-code for workers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ciffelia reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@addaleax addaleax Jul 9, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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 behaviour should match the main thread’s behaviour as closely as possible – in there, we have that process.exitCode is not set, as far as I can tell:

process.on("uncaughtException", () => console.log(process.exitCode));
throw new Error();

prints undefined.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
starkwang
starkwang approved these changes Jul 9, 2018
View reviewed changes
@lundibundi
fixup! workers: fix invalid exit code in parent upon uncaught exception
180abec
@lundibundi

lundibundi commented Jul 9, 2018

Copy link
Copy Markdown
Member Author

If I understand correctly windows CI failure seems unrelated:
https://ci.nodejs.org/job/node-test-binary-windows/18430/COMPILED_BY=vs2017-x86,RUNNER=win2012r2,RUN_SUBSET=1/tapResults/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax
addaleax requested changes Jul 9, 2018
View reviewed changes

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

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.

Labelling with the red X just to make sure this doesn’t get lost, because it already has a few approvals

If I understand correctly windows CI failure seems unrelated

Yes, I think they are nothing to worry about. :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/internal/worker.js Outdated
debug(`[${threadId}] gets fatal exception`);

// set exit code for local worker's 'exit' listeners
process.exitCode = 1;

@addaleax addaleax Jul 9, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

Copying the comment because Github currently hides it:

I think behaviour should match the main thread’s behaviour as closely as possible – in there, we have that process.exitCode is not set, as far as I can tell:

process.on("uncaughtException", () => console.log(process.exitCode));
throw new Error();

prints undefined.

I really think we just need to set process.exitCode in the if (!caught) block once.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lundibundi lundibundi Jul 9, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

That makes sense, but we should probably consider setting the code before calling handler (in both here and for process), to avoid current situation where it emits code 1 but process.exitCode has older value or undefined?
Edit: I mean in 'exit' event.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@addaleax addaleax Jul 9, 2018

Copy link
Copy Markdown
Member

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.

@lundibundi I think that makes sense, yes. But since it affects all Node.js code, not just Workers, we probably should do it in a separate (and maybe even semver-major) PR.

The code you’d probably want to look at – if you want to tackle it yourself – is in process._fatalException in lib/internal/bootstrap/node.js and FatalException() in src/node.cc. We currently have hardcoded values for exiting in the latter function, so I think setting process.exitCode from exit handlers doesn’t have any effect at the moment?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lundibundi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@lundibundi lundibundi Jul 10, 2018

Copy link
Copy Markdown
Member Author

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.

@addaleax Yeah, while looking into this one I looked though those functions (I actually first thought that exit code should be set on c++ side because we are listening on an exit callback from it).
From what I've seen both workers and process use node.cc/EmitExit which actually reevaluates exitCode after the event, so I think it will change the code. But indeed for the uncaught exception this is not the case, as it will always exit with 1 from FatalException() if it wasn't handled (or other hardcoded codes).
Should I open an issue first to track it or it should be okay to just submit PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lundibundi
fixup! workers: fix invalid exit code in parent upon uncaught exception
004c004
addaleax
addaleax approved these changes Jul 9, 2018
View reviewed changes

@addaleax addaleax left a comment

Copy link
Copy Markdown
Member

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.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@addaleax addaleax added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Jul 9, 2018
@addaleax

addaleax commented Jul 9, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/15768/ (edit: ✔️)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cjihrig
cjihrig approved these changes Jul 10, 2018
View reviewed changes
@lundibundi lundibundi mentioned this pull request Jul 10, 2018
process,worker: fix process.exitCode handling for fatalException #21739
Closed
3 of 4 tasks
@addaleax

addaleax commented Jul 10, 2018

Copy link
Copy Markdown
Member

Landed in 1e9c3f8, thanks a lot for the PR! 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax closed this Jul 10, 2018
addaleax pushed a commit that referenced this pull request Jul 10, 2018
@lundibundi @addaleax
workers: fix invalid exit code in parent upon uncaught exception
1e9c3f8
Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.

Fixes: #21707

PR-URL: #21713
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
targos pushed a commit that referenced this pull request Jul 12, 2018
@lundibundi @targos
workers: fix invalid exit code in parent upon uncaught exception
25fef3d
Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.

Fixes: #21707

PR-URL: #21713
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@targos targos mentioned this pull request Jul 17, 2018
v10.7.0 proposal #21851
Merged
This was referenced Jul 18, 2018
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#207
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#208
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#209
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#210
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#211
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@addaleax addaleax addaleax approved these changes
@cjihrig cjihrig cjihrig approved these changes
+4 more reviewers
@ciffelia ciffelia ciffelia left review comments
@hiroppy hiroppy hiroppy approved these changes
@devsnek devsnek devsnek approved these changes
@starkwang starkwang starkwang approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. worker Issues and PRs related to the worker_threads module and Worker API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@lundibundi @hiroppy @addaleax @cjihrig @devsnek @starkwang @ciffelia @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.