worker: ignore --abort-on-uncaught-exception for terminate()
When running Worker threads with `--abort-on-uncaught-exception`, do not abort the process when `worker.terminate()` is called. PR-URL: https://github.com/nodejs/node/pull/26111 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
parent
35e6070f14
commit
85b95cc6a3
@ -32,7 +32,9 @@ static bool AllowWasmCodeGenerationCallback(Local<Context> context,
|
||||
static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
|
||||
HandleScope scope(isolate);
|
||||
Environment* env = Environment::GetCurrent(isolate);
|
||||
return env != nullptr && env->should_abort_on_uncaught_toggle()[0] &&
|
||||
return env != nullptr &&
|
||||
(env->is_main_thread() || !env->is_stopping_worker()) &&
|
||||
env->should_abort_on_uncaught_toggle()[0] &&
|
||||
!env->inside_should_not_abort_on_uncaught_scope();
|
||||
}
|
||||
|
||||
|
24
test/abort/test-worker-abort-uncaught-exception.js
Normal file
24
test/abort/test-worker-abort-uncaught-exception.js
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { spawn } = require('child_process');
|
||||
const { Worker } = require('worker_threads');
|
||||
|
||||
// Tests that --abort-on-uncaught-exception applies to workers as well.
|
||||
|
||||
if (process.argv[2] === 'child') {
|
||||
new Worker('throw new Error("foo");', { eval: true });
|
||||
return;
|
||||
}
|
||||
|
||||
const child = spawn(process.execPath, [
|
||||
'--abort-on-uncaught-exception', __filename, 'child'
|
||||
]);
|
||||
child.on('exit', common.mustCall((code, sig) => {
|
||||
if (common.isWindows) {
|
||||
assert.strictEqual(code, 0xC0000005);
|
||||
} else {
|
||||
assert(['SIGABRT', 'SIGTRAP', 'SIGILL'].includes(sig),
|
||||
`Unexpected signal ${sig}`);
|
||||
}
|
||||
}));
|
@ -0,0 +1,12 @@
|
||||
// Flags: --abort-on-uncaught-exception
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const { Worker } = require('worker_threads');
|
||||
|
||||
// Tests that --abort-on-uncaught-exception does not apply to
|
||||
// termination exceptions.
|
||||
|
||||
const w = new Worker('while(true);', { eval: true });
|
||||
w.on('online', common.mustCall(() => w.terminate()));
|
||||
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));
|
Loading…
x
Reference in New Issue
Block a user