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

Worker exits with code 0 (and not 7) when throwing inside uncaughtException #37996

Closed
Prinzhorn opened this issue Mar 31, 2021 · 0 comments
Closed
Labels
confirmed-bug Issues with confirmed bugs. worker Issues and PRs related to Worker support.

Comments

@Prinzhorn
Copy link

Prinzhorn commented Mar 31, 2021

This is the underlying bug that kept my workaround of #37988 from working.

What steps will reproduce the bug?

index.js

const path = require('path');
const { Worker } = require('worker_threads');
const worker = new Worker(path.join(__dirname, 'worker.js'));

worker
  .on('online', () => {
    console.log('online');
  })
  .on('error', (err) => {
    console.log('error: %s', err);
  })
  .on('exit', (code) => {
    console.log('exit: %s', code);
    process.exit();
  });

worker.js

process.on('uncaughtException', function () {
  throw new Error('uncaughtException');
});

throw new Error('oopsie');
node index.js

online
error: Error: uncaughtException
    at process.<anonymous> (/home/alex/src/issues/worker-exit-code/worker.js:2:9)
    at process.emit (events.js:315:20)
    at internal/process/execution.js:163:25
    at process.workerOnGlobalUncaughtException [as _fatalException] (internal/main/worker_thread.js:194:15)

exit: 0    <================

node worker.js
echo $?
7           <================

How often does it reproduce? Is there a required condition?

10/10 would reproduce again

What is the expected behavior?

Exit code 7 for the worker

Exit code >0 for the worker. Exit codes of workers don't seem to be aligned with the main process, I'm fine with anything other than 0.

What do you see instead?

Exit code 0, which is why my error handling didn't catch it

@Lxxyx Lxxyx added the worker Issues and PRs related to Worker support. label Mar 31, 2021
Linkgoron added a commit to Linkgoron/node that referenced this issue Mar 31, 2021
Change worker exit code when the unhandled exception
handler throws from 0 to 7

fixes: nodejs#37996
Linkgoron added a commit to Linkgoron/node that referenced this issue Mar 31, 2021
Change worker exit code when the unhandled exception
handler throws from 0 to 7

fixes: nodejs#37996
@Linkgoron Linkgoron added the confirmed-bug Issues with confirmed bugs. label Apr 2, 2021
@jasnell jasnell closed this as completed in 6986fa0 Apr 6, 2021
targos pushed a commit that referenced this issue May 1, 2021
Change worker exit code when the unhandled exception
handler throws from 0 to 7

fixes: #37996

PR-URL: #38012
Fixes: #37996
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants