Files
node/test/parallel/test-async-local-storage-http-parser-leak.js
Gerhard Stöbich 4eac93779a src: release context frame in AsyncWrap::EmitDestroy
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>
2026-03-03 14:09:06 +00:00

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);
}));