Skip to content

Commit

Permalink
worker: fix --abort-on-uncaught-exception handling
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
addaleax committed Sep 23, 2020
1 parent efd46e3 commit 5e9f0cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
Environment* env = Environment::GetCurrent(isolate);
return env != nullptr &&
(env->is_main_thread() || !env->is_stopping()) &&
env->abort_on_uncaught_exception() &&
env->should_abort_on_uncaught_toggle()[0] &&
!env->inside_should_not_abort_on_uncaught_scope();
}
Expand Down Expand Up @@ -362,9 +363,6 @@ Environment* CreateEnvironment(
exec_args,
flags,
thread_id);
if (flags & EnvironmentFlags::kOwnsProcessState) {
env->set_abort_on_uncaught_exception(false);
}

#if HAVE_INSPECTOR
if (inspector_parent_handle) {
Expand Down
4 changes: 4 additions & 0 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ Environment::Environment(IsolateData* isolate_data,
inspector_host_port_.reset(
new ExclusiveAccess<HostPort>(options_->debug_options().host_port));

if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) {
set_abort_on_uncaught_exception(false);
}

#if HAVE_INSPECTOR
// We can only create the inspector agent after having cloned the options.
inspector_agent_ = std::make_unique<inspector::Agent>(this);
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-worker-abort-on-uncaught-exception.js
Original file line number Diff line number Diff line change
@@ -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
// Workers.

const w = new Worker('throw new Error()', { eval: true });
w.on('error', common.mustCall());
w.on('exit', common.mustCall((code) => assert.strictEqual(code, 1)));

0 comments on commit 5e9f0cf

Please sign in to comment.