diff options
Diffstat (limited to 'lib/domain.js')
-rw-r--r-- | lib/domain.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/domain.js b/lib/domain.js index b2ffed2741..3dc56c179a 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -73,13 +73,18 @@ const asyncHook = createHook({ if (current !== undefined) { // Enter domain for this cb // We will get the domain through current.get(), because the resource // object's .domain property makes sure it is not garbage collected. + // However, we do need to make the reference to the domain non-weak, + // so that it cannot be garbage collected before the after() hook. + current.incRef(); current.get().enter(); } }, after(asyncId) { const current = pairing.get(asyncId); if (current !== undefined) { // Exit domain for this cb - current.get().exit(); + const domain = current.get(); + current.decRef(); + domain.exit(); } }, destroy(asyncId) { |