Skip to content

Commit fd038a1

Browse files
addaleaxjasnell
authored andcommitted
worker: fix --abort-on-uncaught-exception handling
The `set_abort_on_uncaught_exception(false)` line was supposed to prevent aborting when running Workers in `--abort-on-uncaught-exception` mode, but it was incorrectly set and not checked properly in the should-abort callback. PR-URL: #34724 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Mary Marchini <[email protected]>
1 parent f86e3ea commit fd038a1

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/api/environment.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
4343
Environment* env = Environment::GetCurrent(isolate);
4444
return env != nullptr &&
4545
(env->is_main_thread() || !env->is_stopping()) &&
46+
env->abort_on_uncaught_exception() &&
4647
env->should_abort_on_uncaught_toggle()[0] &&
4748
!env->inside_should_not_abort_on_uncaught_scope();
4849
}

src/env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Environment::Environment(IsolateData* isolate_data,
359359
inspector_host_port_.reset(
360360
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
361361

362-
if (flags & EnvironmentFlags::kOwnsProcessState) {
362+
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
363363
set_abort_on_uncaught_exception(false);
364364
}
365365

Lines 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+
// Workers.
9+
10+
const w = new Worker('throw new Error()', { eval: true });
11+
w.on('error', common.mustCall());
12+
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));

0 commit comments

Comments
 (0)