Skip to content

Commit 513ab0e

Browse files
addaleaxBethGriggs
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 Backport-PR-URL: #34815 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 03d6013 commit 513ab0e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/api/environment.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
4242
Environment* env = Environment::GetCurrent(isolate);
4343
return env != nullptr &&
4444
(env->is_main_thread() || !env->is_stopping()) &&
45+
env->abort_on_uncaught_exception() &&
4546
env->should_abort_on_uncaught_toggle()[0] &&
4647
!env->inside_should_not_abort_on_uncaught_scope();
4748
}
@@ -355,9 +356,6 @@ Environment* CreateEnvironment(
355356
exec_args,
356357
flags,
357358
thread_id);
358-
if (flags & EnvironmentFlags::kOwnsProcessState) {
359-
env->set_abort_on_uncaught_exception(false);
360-
}
361359

362360
#if HAVE_INSPECTOR
363361
if (inspector_parent_handle) {

src/env.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ Environment::Environment(IsolateData* isolate_data,
348348
inspector_host_port_.reset(
349349
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));
350350

351+
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
352+
set_abort_on_uncaught_exception(false);
353+
}
354+
351355
#if HAVE_INSPECTOR
352356
// We can only create the inspector agent after having cloned the options.
353357
inspector_agent_ = std::make_unique<inspector::Agent>(this);
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)