async_hooks: only disable promise hook if wanted · nodejs/node@e74e661 · GitHub
Skip to content

Commit e74e661

Browse files
addaleaxtargos
authored andcommitted
async_hooks: only disable promise hook if wanted
The promise hook has been disabled asynchronously in order to solve issues when an async hook is disabled during a microtask. This means that after scheduling the disable-promise-hook call, attempts to enable it synchronously will later be unintentionally overridden. In order to solve this, make sure that the promise hooks are still no longer desired at the time at which we would disable them. Fixes: #27585 PR-URL: #27590 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 74046ce commit e74e661

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

lib/internal/async_hooks.js

Lines changed: 15 additions & 2 deletions

src/async_wrap.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,10 @@ static void EnablePromiseHook(const FunctionCallbackInfo<Value>& args) {
334334
static void DisablePromiseHook(const FunctionCallbackInfo<Value>& args) {
335335
Isolate* isolate = args.GetIsolate();
336336

337-
// Delay the call to `RemovePromiseHook` because we might currently be
338-
// between the `before` and `after` calls of a Promise.
339-
isolate->EnqueueMicrotask([](void* data) {
340-
// The per-Isolate API provides no way of knowing whether there are multiple
341-
// users of the PromiseHook. That hopefully goes away when V8 introduces
342-
// a per-context API.
343-
Isolate* isolate = static_cast<Isolate*>(data);
344-
isolate->SetPromiseHook(nullptr);
345-
}, static_cast<void*>(isolate));
337+
// The per-Isolate API provides no way of knowing whether there are multiple
338+
// users of the PromiseHook. That hopefully goes away when V8 introduces
339+
// a per-context API.
340+
isolate->SetPromiseHook(nullptr);
346341
}
347342

348343

Lines changed: 17 additions & 0 deletions

0 commit comments

Comments
 (0)