Skip to content

Commit e554bb4

Browse files
addaleaxjasnell
authored andcommitted
async_hooks: only set up hooks if used
PR-URL: #13177 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Andreas Madsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 287b11d commit e554bb4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/async_hooks.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ const before_symbol = Symbol('before');
4949
const after_symbol = Symbol('after');
5050
const destroy_symbol = Symbol('destroy');
5151

52-
// Setup the callbacks that node::AsyncWrap will call when there are hooks to
53-
// process. They use the same functions as the JS embedder API.
54-
async_wrap.setupHooks({ init,
55-
before: emitBeforeN,
56-
after: emitAfterN,
57-
destroy: emitDestroyN });
52+
let setupHooksCalled = false;
5853

5954
// Used to fatally abort the process if a callback throws.
6055
function fatalError(e) {
@@ -103,6 +98,16 @@ class AsyncHook {
10398
if (hooks_array.includes(this))
10499
return;
105100

101+
if (!setupHooksCalled) {
102+
setupHooksCalled = true;
103+
// Setup the callbacks that node::AsyncWrap will call when there are
104+
// hooks to process. They use the same functions as the JS embedder API.
105+
async_wrap.setupHooks({ init,
106+
before: emitBeforeN,
107+
after: emitAfterN,
108+
destroy: emitDestroyN });
109+
}
110+
106111
// createHook() has already enforced that the callbacks are all functions,
107112
// so here simply increment the count of whether each callbacks exists or
108113
// not.

0 commit comments

Comments
 (0)