GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — workers: fix invalid exit code in parent upon uncaught exception by lundibundi · Pull Request #21713 · nodejs/node Conversation
Member
Now worker.on('exit') reports correct exit code (1) if worker has exited Fixes: #21707 Checklist
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. All reactions
Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.
Fixes: nodejs#21707
devsnek
approved these changes
hiroppy
approved these changes
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
ciffelia
reviewed
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree – I think you want to move this into the
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
|
If I understand correctly windows CI failure seems unrelated: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| debug(`[${threadId}] gets fatal exception`); | ||
|
|
||
| // set exit code for local worker's 'exit' listeners | ||
| process.exitCode = 1; |
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
CI: https://ci.nodejs.org/job/node-test-pull-request/15768/ (edit: ✔️) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Landed in 1e9c3f8, thanks a lot for the PR! 🎉 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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]>
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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.