Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dab3d71

Browse filesBrowse files
addaleaxrvagg
authored andcommitted
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: #26111 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 778db67 commit dab3d71
Copy full SHA for dab3d71

File tree

Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed
Open diff view settings
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ static bool AllowWasmCodeGenerationCallback(Local<Context> context,
3232
static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
3333
HandleScope scope(isolate);
3434
Environment* env = Environment::GetCurrent(isolate);
35-
return env != nullptr && env->should_abort_on_uncaught_toggle()[0] &&
35+
return env != nullptr &&
36+
(env->is_main_thread() || !env->is_stopping_worker()) &&
37+
env->should_abort_on_uncaught_toggle()[0] &&
3638
!env->inside_should_not_abort_on_uncaught_scope();
3739
}
3840

Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { spawn } = require('child_process');
5+
const { Worker } = require('worker_threads');
6+
7+
// Tests that --abort-on-uncaught-exception applies to workers as well.
8+
9+
if (process.argv[2] === 'child') {
10+
new Worker('throw new Error("foo");', { eval: true });
11+
return;
12+
}
13+
14+
const child = spawn(process.execPath, [
15+
'--abort-on-uncaught-exception', __filename, 'child'
16+
]);
17+
child.on('exit', common.mustCall((code, sig) => {
18+
if (common.isWindows) {
19+
assert.strictEqual(code, 0xC0000005);
20+
} else {
21+
assert(['SIGABRT', 'SIGTRAP', 'SIGILL'].includes(sig),
22+
`Unexpected signal ${sig}`);
23+
}
24+
}));
Collapse file
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Flags: --abort-on-uncaught-exception
2+
'use strict';
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { Worker } = require('worker_threads');
6+
7+
// Tests that --abort-on-uncaught-exception does not apply to
8+
// termination exceptions.
9+
10+
const w = new Worker('while(true);', { eval: true });
11+
w.on('online', common.mustCall(() => w.terminate()));
12+
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.