Browse Source

async_hooks: move restoreTmpHooks call to init

This fixes an error that could occure by nesting async_hooks calls

PR-URL: https://github.com/nodejs/node/pull/14054
Ref: https://github.com/nodejs/node/pull/13755#issuecomment-312616004
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
v6
Ruben Bridgewater 7 years ago
committed by Andreas Madsen
parent
commit
8a830350b2
No known key found for this signature in database GPG Key ID: 2FEE61B3C9E40F20
  1. 10
      lib/async_hooks.js
  2. 19
      test/parallel/test-async-hooks-enable-recursive.js

10
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();
}
}

19
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());
}));
Loading…
Cancel
Save