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

When worker thread throw an error, main thread recieves exit code 0 instead of 1 #21707

Closed
ciffelia opened this issue Jul 8, 2018 · 3 comments
Labels
good first issue Issues that are suitable for first-time contributors. worker Issues and PRs related to Worker support.

Comments

@ciffelia
Copy link

ciffelia commented Jul 8, 2018

  • Version: v10.6.0
  • Platform:
    • Windows 64-bit
    • Linux 29d0523d5d87 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 Linux (Alpine Linux on Docker)
    • Linux 30e69b847957 4.9.87-linuxkit-aufs #1 SMP Wed Mar 14 15:12:16 UTC 2018 x86_64 GNU/Linux (Debian on Docker)
  • Subsystem: worker_threads

Reproduction code

const { Worker, isMainThread } = require('worker_threads');

if (isMainThread) {
  const worker = new Worker(__filename);
  worker.on('error', err => {
    console.log(`Worker threw an error: ${err.message}`);
  });
  worker.on('exit', code => {
    console.log(`Worker finished with exit code ${code}`);
  });
} else {
  throw new Error('error!');
}

Expected output

Worker threw an error: error!
Worker finished with exit code 1

Actual output

Worker threw an error: error!
Worker finished with exit code 0
@targos targos added the worker Issues and PRs related to Worker support. label Jul 8, 2018
@targos
Copy link
Member

targos commented Jul 8, 2018

@nodejs/workers

@addaleax
Copy link
Member

addaleax commented Jul 8, 2018

I think it might be enough to set process.exitCode in fatalException in lib/internal/worker.js?

@addaleax addaleax added the good first issue Issues that are suitable for first-time contributors. label Jul 8, 2018
@lundibundi
Copy link
Member

I've been looking into this one and would like to work on it, is it okay?

lundibundi added a commit to lundibundi/node that referenced this issue Jul 8, 2018
Now worker.on('exit') reports correct exit code (1) if worker has exited
with uncaught exception.

Fixes: nodejs#21707
targos pushed a commit that referenced this issue Jul 12, 2018
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 <me@gus.host>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Weijia Wang <starkwang@126.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are suitable for first-time contributors. worker Issues and PRs related to Worker support.
Projects
None yet
Development

No branches or pull requests

4 participants