summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/async_hooks.js10
-rw-r--r--test/parallel/test-async-hooks-enable-recursive.js19
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/async_hooks.js b/lib/async_hooks.js
index a730738c0f..42d04f0630 100644
--- a/lib/async_hooks.js
+++ b/lib/async_hooks.js
@@ -335,11 +335,6 @@ function emitInitS(asyncId, type, triggerAsyncId, resource) {
throw new RangeError('triggerAsyncId must be an unsigned integer');
init(asyncId, type, triggerAsyncId, resource);
-
- // Isn't null if hooks were added/removed while the hooks were running.
- if (tmp_active_hooks_array !== null) {
- restoreTmpHooks();
- }
}
function emitHookFactory(symbol, name) {
@@ -442,6 +437,11 @@ function init(asyncId, type, triggerAsyncId, resource) {
fatalError(e);
}
processing_hook = false;
+
+ // Isn't null if hooks were added/removed while the hooks were running.
+ if (tmp_active_hooks_array !== null) {
+ restoreTmpHooks();
+ }
}
diff --git a/test/parallel/test-async-hooks-enable-recursive.js b/test/parallel/test-async-hooks-enable-recursive.js
new file mode 100644
index 0000000000..bcb0dcc0ce
--- /dev/null
+++ b/test/parallel/test-async-hooks-enable-recursive.js
@@ -0,0 +1,19 @@
+'use strict';
+
+const common = require('../common');
+const async_hooks = require('async_hooks');
+const fs = require('fs');
+
+const nestedHook = async_hooks.createHook({
+ init: common.mustCall()
+});
+
+async_hooks.createHook({
+ init: common.mustCall((id, type) => {
+ nestedHook.enable();
+ }, 2)
+}).enable();
+
+fs.access(__filename, common.mustCall(() => {
+ fs.access(__filename, common.mustCall());
+}));