Skip to content

Commit

Permalink
async_hooks: move restoreTmpHooks call to init
Browse files Browse the repository at this point in the history
This fixes an error that could occure by nesting async_hooks calls

PR-URL: #14054
Ref: #13755 (comment)
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Trevor Norris <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Andreas Madsen <[email protected]>
  • Loading branch information
BridgeAR authored and AndreasMadsen committed Jul 13, 2017
1 parent 5ffb5b6 commit 8a83035
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
}


Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-async-hooks-enable-recursive.js
Original file line number Diff line number Diff line change
@@ -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());
}));

0 comments on commit 8a83035

Please sign in to comment.