Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
async_hooks: move restoreTmpHooks call to init
This fixes an error that could occure by nesting async_hooks calls
  • Loading branch information
BridgeAR committed Jul 10, 2017
commit 120f2e26f5af50d803fed9bad663cad37556b3a3
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 crypto = require('crypto');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're using crypto you need:

if (!common.hasCrypto)
  common.skip('missing crypto');

AFAICT this should work with fs or stream...

Copy link
Copy Markdown
Member

@AndreasMadsen AndreasMadsen Jul 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fs should work (for example fs.access(__filename, () => {})).


const nestedHook = async_hooks.createHook({
init: common.mustCall()
});

async_hooks.createHook({
init: common.mustCall((id, type) => {
nestedHook.enable();
}, 2)
}).enable();

crypto.randomBytes(1, common.mustCall(() => {
crypto.randomBytes(1, common.mustCall());
}));