mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
b376965e50
commit
503900b463
1 changed files with 7 additions and 9 deletions
|
@ -21,7 +21,6 @@ const {
|
|||
executionAsyncId,
|
||||
triggerAsyncId,
|
||||
// Private API
|
||||
hasAsyncIdStack,
|
||||
getHookArrays,
|
||||
enableHooks,
|
||||
disableHooks,
|
||||
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue