Skip to content

Commit

Permalink
async_hooks: ensure proper handling in runInAsyncScope
Browse files Browse the repository at this point in the history
We should never try to manually run emitAfter in case of an error,
the exception handler will do it for us, if we're going to recover.

PR-URL: #30965
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
apapirovski authored and MylesBorins committed Dec 17, 2019
1 parent 3abcb69 commit e10917f
Showing 1 changed file with 7 additions and 9 deletions.
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

0 comments on commit e10917f

Please sign in to comment.