Skip to content

Commit 3211eff

Browse files
BridgeARaddaleax
authored andcommitted
async_hooks: move restoreTmpHooks call to init
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]>
1 parent 36c267c commit 3211eff

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

‎lib/async_hooks.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,6 @@ function emitInitS(asyncId, type, triggerAsyncId, resource){
335335
thrownewRangeError('triggerAsyncId must be an unsigned integer');
336336

337337
init(asyncId,type,triggerAsyncId,resource);
338-
339-
// Isn't null if hooks were added/removed while the hooks were running.
340-
if(tmp_active_hooks_array!==null){
341-
restoreTmpHooks();
342-
}
343338
}
344339

345340
functionemitHookFactory(symbol,name){
@@ -442,6 +437,11 @@ function init(asyncId, type, triggerAsyncId, resource){
442437
fatalError(e);
443438
}
444439
processing_hook=false;
440+
441+
// Isn't null if hooks were added/removed while the hooks were running.
442+
if(tmp_active_hooks_array!==null){
443+
restoreTmpHooks();
444+
}
445445
}
446446

447447

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
constcommon=require('../common');
4+
constasync_hooks=require('async_hooks');
5+
constfs=require('fs');
6+
7+
constnestedHook=async_hooks.createHook({
8+
init: common.mustCall()
9+
});
10+
11+
async_hooks.createHook({
12+
init: common.mustCall((id,type)=>{
13+
nestedHook.enable();
14+
},2)
15+
}).enable();
16+
17+
fs.access(__filename,common.mustCall(()=>{
18+
fs.access(__filename,common.mustCall());
19+
}));

0 commit comments

Comments
(0)