Skip to content

Commit c6be79a

Browse files
apapirovskitargos
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 <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 42ccf22 commit c6be79a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/async_hooks.js

+7-9
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)