Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: do not crash if ToggleAsyncHook fails during termination #34362

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/inspector_agent.cc
Expand Up @@ -841,13 +841,14 @@ void Agent::DisableAsyncHook() {

void Agent::ToggleAsyncHook(Isolate* isolate,
const Global<Function>& fn) {
if (!parent_env_->can_call_into_js()) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better if some comments are added about when this would happen, maybe something like The inspector agent might attempt to toggle the inspector async hooks to stop tracking async call stacks when the Node.js instance is shutting down and is not supposed to execute JS anymore. To avoid crashing we'll just make it a noop and stop tracking async call stacks here (I am assuming it's fine to just stop tracking because we probably don't care when the instance is shutting down?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although to quote my comment in #27261 (comment) this still feels like a bug - we are doing inspector client cleanups after the client is being disconnected from the frontend. But I guess a fix like this wouldn't hurt and does the trick for most users which is what matters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a side note I think an ultimate fix would be to correct the state management of either waiting_for_frontend_, waiting_for_sessions_disconnect_ or waiting_for_resume_, or add another one to the mix (though I have no idea how)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added a comment that explains that if we hit this condition, no async events are going to be emitted anyway, and added a link to your comment here 👍

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.");
Expand Down