test: close WebAssembly test HTTP servers

Unreferencing listeners leaves accepted connections alive until the
keep-alive timeout. Close each single-use connection and its server
when the response closes, including intentionally destroyed responses.

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/65980
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
This commit is contained in:
Filip Skokan authored and Antoine du Hamel committed 2026-09-16 21:12:14 +02:00
1 parent f23847a122
commit f523342bcd
1 file changed
+7 -1
+7 -1
View File
@@ -16,7 +16,13 @@ const simpleWasmBytes = fixtures.readSync('simple.wasm');
// Sets up an HTTP server with the given response handler and calls fetch() to
// obtain a Response from the newly created server.
async function testRequest(handler) {
const server = createServer((_, res) => handler(res)).unref().listen(0);
const server = createServer(common.mustCall((_, res) => {
res.setHeader('Connection', 'close');
res.once('close', common.mustCall(() => {
server.close(common.mustCall());
}));
handler(res);
})).listen(0);
await events.once(server, 'listening');
const { port } = server.address();
return fetch(`http://127.0.0.1:${port}/foo.wasm`);