mirror of
https://github.com/nodejs/node.git
synced 2025-05-08 12:49:23 +00:00

In cases where libraries create AsyncResources which may be emitting more events depending on usage, the only way to ensure that destroy is called properly is by calling it when the resource gets garbage collected. Fixes: https://github.com/nodejs/node/issues/16153 PR-URL: https://github.com/nodejs/node/pull/16998 Fixes: https://github.com/nodejs/node/issues/16153 Reviewed-By: Andreas Madsen <amwebdk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
22 lines
512 B
JavaScript
22 lines
512 B
JavaScript
'use strict';
|
|
// Flags: --expose_gc
|
|
|
|
// This test ensures that userland-only AsyncResources cause a destroy event to
|
|
// be emitted when they get gced.
|
|
|
|
const common = require('../common');
|
|
const async_hooks = require('async_hooks');
|
|
|
|
const hook = async_hooks.createHook({
|
|
destroy: common.mustCall(1) // only 1 immediate is destroyed
|
|
}).enable();
|
|
|
|
new async_hooks.AsyncResource('foobar', { requireManualDestroy: true });
|
|
|
|
setImmediate(() => {
|
|
global.gc();
|
|
setImmediate(() => {
|
|
hook.disable();
|
|
});
|
|
});
|