Node: When worker thread throw an error, main thread recieves exit code 0 instead of 1

Created on 8 Jul 2018  路  3Comments  路  Source: nodejs/node

  • 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
good first issue worker

Most helpful comment

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

All 3 comments

@nodejs/workers

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cong88 picture cong88  路  3Comments

loretoparisi picture loretoparisi  路  3Comments

Brekmister picture Brekmister  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

jmichae3 picture jmichae3  路  3Comments