summaryrefslogtreecommitdiff
path: root/lib/domain.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-06-19 19:24:14 -0700
committerRich Trott <rtrott@gmail.com>2019-07-24 20:40:42 -0700
commit43e5478e2f51343b66f4d243bb4800d8e422f764 (patch)
treec2aea9ecb0b8187156fb1760da086cf356df1044 /lib/domain.js
parent49eb2b8e2a1d964fe78d9dcf4bb1f6c7e967a931 (diff)
downloadnode-new-43e5478e2f51343b66f4d243bb4800d8e422f764.tar.gz
domain: use strong reference to domain while active
When an uncaught exception is thrown inside a domain, the domain is removed from the stack as of 43a51708589ac789ce08beaeb49d6d778dfbdc49. This means that it might not be kept alive as an object anymore, and may be garbage collected before the `after()` hook can run, which tries to exit it as well. Resolve that by making references to the domain strong while it is active. Fixes: https://github.com/nodejs/node/issues/28275 PR-URL: https://github.com/nodejs/node/pull/28313 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/domain.js')
-rw-r--r--lib/domain.js7
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) {