mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Release the async context frame in AsyncWrap::EmitDestroy to allow gc to collect it. This is in special relevant for reused resources like HTTPParser otherwise they might keep ALS stores alive. PR-URL: https://github.com/nodejs/node/pull/61995 Fixes: https://github.com/nodejs/node/issues/61882 Refs: https://github.com/nodejs/node/pull/48528 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
30 lines
707 B
JavaScript
30 lines
707 B
JavaScript
// Flags: --expose-gc
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { onGC } = require('../common/gc');
|
|
const assert = require('node:assert');
|
|
const { AsyncLocalStorage } = require('node:async_hooks');
|
|
const { freeParser, parsers, HTTPParser } = require('_http_common');
|
|
|
|
let storeGCed = false;
|
|
|
|
const als = new AsyncLocalStorage();
|
|
|
|
function test() {
|
|
const store = {};
|
|
onGC(store, { ongc: common.mustCall(() => { storeGCed = true; }) });
|
|
let parser;
|
|
als.run(store, common.mustCall(() => {
|
|
parser = parsers.alloc();
|
|
parser.initialize(HTTPParser.RESPONSE, {});
|
|
}));
|
|
freeParser(parser);
|
|
}
|
|
|
|
test();
|
|
global.gc();
|
|
setImmediate(common.mustCall(() => {
|
|
assert.ok(storeGCed);
|
|
}));
|