Skip to content

Commit 5e9f0cf

Browse files
committed
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 efd46e3 commit 5e9f0cf

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
@@ -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
}
@@ -362,9 +363,6 @@ Environment* CreateEnvironment(
362363
exec_args,
363364
flags,
364365
thread_id);
365-
if (flags & EnvironmentFlags::kOwnsProcessState) {
366-
env->set_abort_on_uncaught_exception(false);
367-
}
368366

369367
#if HAVE_INSPECTOR
370368
if (inspector_parent_handle) {

src/env.cc

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

359+
if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
360+
set_abort_on_uncaught_exception(false);
361+
}
362+
359363
#if HAVE_INSPECTOR
360364
// We can only create the inspector agent after having cloned the options.
361365
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)