worker: fix process._fatalException return type
This makes sure `process._fatalException()` returns a boolean when run inside of a worker. PR-URL: https://github.com/nodejs/node/pull/29706 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
This commit is contained in:
parent
c2ce8d0547
commit
aea9a0f77d
@ -166,7 +166,10 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
|
||||
}
|
||||
debug(`[${threadId}] uncaught exception handled = ${handled}`);
|
||||
|
||||
if (!handled) {
|
||||
if (handled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let serialized;
|
||||
try {
|
||||
const { serializeError } = require('internal/error-serdes');
|
||||
@ -185,7 +188,6 @@ function workerOnGlobalUncaughtException(error, fromPromise) {
|
||||
clearAsyncIdStack();
|
||||
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Patch the global uncaught exception handler so it gets picked up by
|
||||
|
25
test/parallel/test-worker-non-fatal-uncaught-exception.js
Normal file
25
test/parallel/test-worker-non-fatal-uncaught-exception.js
Normal file
@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { Worker } = require('worker_threads');
|
||||
|
||||
// Check that `process._fatalException()` returns a boolean when run inside a
|
||||
// worker.
|
||||
|
||||
// Do not use isMainThread so that this test itself can be run inside a Worker.
|
||||
if (!process.env.HAS_STARTED_WORKER) {
|
||||
process.env.HAS_STARTED_WORKER = 1;
|
||||
const w = new Worker(__filename);
|
||||
w.on('exit', common.mustCall((code) => {
|
||||
assert.strictEqual(code, 0);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
process.once('uncaughtException', () => {
|
||||
process.nextTick(() => {
|
||||
assert.strictEqual(res, true);
|
||||
});
|
||||
});
|
||||
|
||||
const res = process._fatalException(new Error());
|
Loading…
x
Reference in New Issue
Block a user