summaryrefslogtreecommitdiff
path: root/test/parallel/test-domain-async-id-map-leak.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-domain-async-id-map-leak.js')
-rw-r--r--test/parallel/test-domain-async-id-map-leak.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-domain-async-id-map-leak.js b/test/parallel/test-domain-async-id-map-leak.js
new file mode 100644
index 0000000000..e720241841
--- /dev/null
+++ b/test/parallel/test-domain-async-id-map-leak.js
@@ -0,0 +1,36 @@
+// Flags: --expose-gc
+'use strict';
+const common = require('../common');
+const onGC = require('../common/ongc');
+const assert = require('assert');
+const async_hooks = require('async_hooks');
+const domain = require('domain');
+const EventEmitter = require('events');
+
+// This test makes sure that the (async id → domain) map which is part of the
+// domain module does not get in the way of garbage collection.
+// See: https://github.com/nodejs/node/issues/23862
+
+let d = domain.create();
+d.run(() => {
+ const resource = new async_hooks.AsyncResource('TestResource');
+ const emitter = new EventEmitter();
+
+ d.remove(emitter);
+ d.add(emitter);
+
+ emitter.linkToResource = resource;
+ assert.strictEqual(emitter.domain, d);
+ assert.strictEqual(resource.domain, d);
+
+ // This would otherwise be a circular chain now:
+ // emitter → resource → async id ⇒ domain → emitter.
+ // Make sure that all of these objects are released:
+
+ onGC(resource, { ongc: common.mustCall() });
+ onGC(d, { ongc: common.mustCall() });
+ onGC(emitter, { ongc: common.mustCall() });
+});
+
+d = null;
+global.gc();