Skip to content

Commit a9fad85

Browse files
apapirovskiBethGriggs
authored andcommitted
async_hooks: ensure proper handling in runInAsyncScope
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 <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 95eb1c2 commit a9fad85

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/async_hooks.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const {
2121
executionAsyncId,
2222
triggerAsyncId,
2323
// Private API
24-
hasAsyncIdStack,
2524
getHookArrays,
2625
enableHooks,
2726
disableHooks,
@@ -172,14 +171,13 @@ class AsyncResource {
172171
runInAsyncScope(fn, thisArg, ...args) {
173172
const asyncId = this[async_id_symbol];
174173
emitBefore(asyncId, this[trigger_async_id_symbol]);
175-
try {
176-
if (thisArg === undefined)
177-
return fn(...args);
178-
return ReflectApply(fn, thisArg, args);
179-
} finally {
180-
if (hasAsyncIdStack())
181-
emitAfter(asyncId);
182-
}
174+
175+
const ret = thisArg === undefined ?
176+
fn(...args) :
177+
ReflectApply(fn, thisArg, args);
178+
179+
emitAfter(asyncId);
180+
return ret;
183181
}
184182

185183
emitDestroy() {

0 commit comments

Comments
 (0)