diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-07-14 18:21:03 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-07-22 02:12:43 +0300 |
commit | 687dbd85263f433cc351c6daa83f9296a1d0bb4f (patch) | |
tree | 69ba799f3e8877f743078efd366d762bfcdb1b78 /src/inspector_agent.cc | |
parent | 08b6335c9c33a0e0af69a85a75b40bd8f6e163c6 (diff) |
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 https://github.com/nodejs/node/issues/34361.
Fixes: https://github.com/nodejs/node/issues/34361
PR-URL: https://github.com/nodejs/node/pull/34362
Fixes: https://github.com/nodejs/node/issues/27261
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_agent.cc')
-rw-r--r-- | src/inspector_agent.cc | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 13ebffdc049..f81c16e91ab 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -841,13 +841,18 @@ void Agent::DisableAsyncHook() { void Agent::ToggleAsyncHook(Isolate* isolate, const Global<Function>& fn) { + // Guard against running this during cleanup -- no async events will be + // emitted anyway at that point anymore, and calling into JS is not possible. + // This should probably not be something we're attempting in the first place, + // Refs: https://github.com/nodejs/node/pull/34362#discussion_r456006039 + if (!parent_env_->can_call_into_js()) return; CHECK(parent_env_->has_run_bootstrapping_code()); HandleScope handle_scope(isolate); CHECK(!fn.IsEmpty()); auto context = parent_env_->context(); v8::TryCatch try_catch(isolate); USE(fn.Get(isolate)->Call(context, Undefined(isolate), 0, nullptr)); - if (try_catch.HasCaught()) { + if (try_catch.HasCaught() && !try_catch.HasTerminated()) { PrintCaughtException(isolate, context, try_catch); FatalError("\nnode::inspector::Agent::ToggleAsyncHook", "Cannot toggle Inspector's AsyncHook, please report this."); |