Skip to content

Commit d6ee1fd

Browse files
addaleaxMylesBorins
authored andcommitted
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 #34361. Fixes: #34361 PR-URL: #34362 Fixes: #27261 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3fda3d4 commit d6ee1fd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/inspector_agent.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -917,13 +917,18 @@ void Agent::DisableAsyncHook() {
917917

918918
void Agent::ToggleAsyncHook(Isolate* isolate,
919919
const Global<Function>& fn) {
920+
// Guard against running this during cleanup -- no async events will be
921+
// emitted anyway at that point anymore, and calling into JS is not possible.
922+
// This should probably not be something we're attempting in the first place,
923+
// Refs: https://github.com./nodejs/node/pull/34362#discussion_r456006039
924+
if (!parent_env_->can_call_into_js()) return;
920925
CHECK(parent_env_->has_run_bootstrapping_code());
921926
HandleScope handle_scope(isolate);
922927
CHECK(!fn.IsEmpty());
923928
auto context = parent_env_->context();
924929
v8::TryCatch try_catch(isolate);
925930
USE(fn.Get(isolate)->Call(context, Undefined(isolate), 0, nullptr));
926-
if (try_catch.HasCaught()) {
931+
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
927932
PrintCaughtException(isolate, context, try_catch);
928933
FatalError("\nnode::inspector::Agent::ToggleAsyncHook",
929934
"Cannot toggle Inspector's AsyncHook, please report this.");

0 commit comments

Comments
 (0)