2020-02-26 09:38:48 +03:00
|
|
|
'use strict';
|
2025-05-06 20:00:56 +02:00
|
|
|
// Flags: --expose_gc --expose-internals
|
2020-02-26 09:38:48 +03:00
|
|
|
|
|
|
|
// This test ensures that AsyncLocalStorage gets gced once it was disabled
|
|
|
|
// and no strong references remain in userland.
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
2025-05-06 20:00:56 +02:00
|
|
|
const AsyncContextFrame = require('internal/async_context_frame');
|
2024-08-13 18:28:21 +08:00
|
|
|
const { onGC } = require('../common/gc');
|
2020-02-26 09:38:48 +03:00
|
|
|
|
|
|
|
let asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
|
2020-03-14 09:06:06 +03:00
|
|
|
asyncLocalStorage.run({}, () => {
|
2020-02-26 09:38:48 +03:00
|
|
|
asyncLocalStorage.disable();
|
|
|
|
|
|
|
|
onGC(asyncLocalStorage, { ongc: common.mustCall() });
|
|
|
|
});
|
|
|
|
|
2025-05-06 20:00:56 +02:00
|
|
|
if (AsyncContextFrame.enabled) {
|
|
|
|
// This disable() is needed to remove reference form AsyncContextFrame
|
|
|
|
// created during exit of run() to the AsyncLocalStore instance.
|
|
|
|
asyncLocalStorage.disable();
|
|
|
|
}
|
|
|
|
|
2020-02-26 09:38:48 +03:00
|
|
|
asyncLocalStorage = null;
|
|
|
|
global.gc();
|