Skip to content

Commit 643a109

Browse files
committed
src: do not crash if ToggleAsyncHook fails during termination
In the termination case, we should not crash. There’s also no harm being done by ignoring the termination exception here, since the thread is about to be torn down anyway. Also, add a guard against running this during shutdown. That is the likely cause of nodejs#34361. Fixes: nodejs#34361
1 parent 4195c31 commit 643a109

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/inspector_agent.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,13 +841,14 @@ void Agent::DisableAsyncHook() {
841841

842842
void Agent::ToggleAsyncHook(Isolate* isolate,
843843
const Global<Function>& fn) {
844+
if (!parent_env_->can_call_into_js()) return;
844845
CHECK(parent_env_->has_run_bootstrapping_code());
845846
HandleScope handle_scope(isolate);
846847
CHECK(!fn.IsEmpty());
847848
auto context = parent_env_->context();
848849
v8::TryCatch try_catch(isolate);
849850
USE(fn.Get(isolate)->Call(context, Undefined(isolate), 0, nullptr));
850-
if (try_catch.HasCaught()) {
851+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
851852
PrintCaughtException(isolate, context, try_catch);
852853
FatalError("\nnode::inspector::Agent::ToggleAsyncHook",
853854
"Cannot toggle Inspector's AsyncHook, please report this.");

0 commit comments

Comments
 (0)