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

async_hooks: proper handling for AH in runInAsyncScope #30965

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
executionAsyncId,
triggerAsyncId,
// Private API
hasAsyncIdStack,
getHookArrays,
enableHooks,
disableHooks,
Expand Down Expand Up @@ -172,14 +171,13 @@ class AsyncResource {
runInAsyncScope(fn, thisArg, ...args) {
const asyncId = this[async_id_symbol];
emitBefore(asyncId, this[trigger_async_id_symbol]);
try {
if (thisArg === undefined)
return fn(...args);
return ReflectApply(fn, thisArg, args);
} finally {
if (hasAsyncIdStack())
emitAfter(asyncId);
}

const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);

emitAfter(asyncId);
return ret;
}

emitDestroy() {
Expand Down