diff options
author | Nitzan Uziely <linkgoron@gmail.com> | 2021-04-01 00:13:28 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-05-01 13:31:16 +0300 |
commit | b6f4d790d313fed0b942b752775958eaeba707ff (patch) | |
tree | 4f7ec5a6327b233571d89b109ba65d4d97bd6945 /lib | |
parent | f1aae4334973132d8d78091d3300a4bf962c7bd9 (diff) |
worker: fix exit code for error thrown in handler
Change worker exit code when the unhandled exception
handler throws from 0 to 7
fixes: https://github.com/nodejs/node/issues/37996
PR-URL: https://github.com/nodejs/node/pull/38012
Fixes: https://github.com/nodejs/node/issues/37996
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/main/worker_thread.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 75bc13d888a..6f8cb6b942b 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -193,10 +193,12 @@ port.on('message', (message) => { function workerOnGlobalUncaughtException(error, fromPromise) { debug(`[${threadId}] gets uncaught exception`); let handled = false; + let handlerThrew = false; try { handled = onGlobalUncaughtException(error, fromPromise); } catch (e) { error = e; + handlerThrew = true; } debug(`[${threadId}] uncaught exception handled = ${handled}`); @@ -204,6 +206,16 @@ function workerOnGlobalUncaughtException(error, fromPromise) { return true; } + if (!process._exiting) { + try { + process._exiting = true; + process.exitCode = 1; + if (!handlerThrew) { + process.emit('exit', process.exitCode); + } + } catch {} + } + let serialized; try { const { serializeError } = require('internal/error_serdes'); |