From e07237ce9fea9a7bdc315018994334fe1055b934 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Thu, 13 Feb 2020 23:48:09 -0800 Subject: [PATCH] Revert "async_hooks: ensure proper handling in runInAsyncScope" This reverts commit a9fad8524cb5db21fb70614561e0418f3a10199b. --- lib/async_hooks.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/async_hooks.js b/lib/async_hooks.js index 31e4ad4e3e56d0..be32f6d1102bbd 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -21,6 +21,7 @@ const { executionAsyncId, triggerAsyncId, // Private API + hasAsyncIdStack, getHookArrays, enableHooks, disableHooks, @@ -171,13 +172,14 @@ class AsyncResource { runInAsyncScope(fn, thisArg, ...args) { const asyncId = this[async_id_symbol]; emitBefore(asyncId, this[trigger_async_id_symbol]); - - const ret = thisArg === undefined ? - fn(...args) : - ReflectApply(fn, thisArg, args); - - emitAfter(asyncId); - return ret; + try { + if (thisArg === undefined) + return fn(...args); + return ReflectApply(fn, thisArg, args); + } finally { + if (hasAsyncIdStack()) + emitAfter(asyncId); + } } emitDestroy() {