From e78ce826415b8d64e9cb2c3b40ba18eadb83f23d Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 22 Nov 2023 17:37:40 +0100 Subject: [PATCH] fix: do not call `after()` `async_hook` for `asyncId` 0 (#40574) fix: do not call after() async_hook for asyncId 0 --- shell/common/node_bindings.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index 007f0bd6d05..f58a8298bb0 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -279,8 +279,11 @@ void ErrorMessageListener(v8::Local message, // Analogous to node/lib/internal/process/execution.js#L176-L180 if (env->async_hooks()->fields()[node::AsyncHooks::kAfter]) { while (env->async_hooks()->fields()[node::AsyncHooks::kStackLength]) { - node::AsyncWrap::EmitAfter(env, env->execution_async_id()); - env->async_hooks()->pop_async_context(env->execution_async_id()); + double id = env->execution_async_id(); + // Do not call EmitAfter for asyncId 0. + if (id != 0) + node::AsyncWrap::EmitAfter(env, id); + env->async_hooks()->pop_async_context(id); } }