From d1b9f78e5b81a849f6dd4c9376e85b7e449c0c6c Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Thu, 19 Nov 2026 11:48:23 +0100 Subject: [PATCH] test: limit concurrency in gc-http-client tests The tests started one request chain per CPU, each issuing a new request on every event loop turn until the first response arrived. On a loaded macOS host this put more than 128 connections in flight, overflowing the listen queue. The kernel then drops an incomplete connection and answers its final ACK with a RST, so the client fails with `connect ECONNRESET`. Use a fixed number of concurrent requests and a fixed total instead. Drive-by: the error handler in test-gc-http-client-onerror rethrows, fix the comment that says it does nothing. Signed-off-by: Matteo Collina --- .../sequential/test-gc-http-client-onerror.js | 45 +++++++++---------- test/sequential/test-gc-http-client.js | 43 +++++++++--------- 2 files changed, 41 insertions(+), 47 deletions(-) diff --git a/test/sequential/test-gc-http-client-onerror.js b/test/sequential/test-gc-http-client-onerror.js index 1c311c6a9b64..b498f3c77331 100644 --- a/test/sequential/test-gc-http-client-onerror.js +++ b/test/sequential/test-gc-http-client-onerror.js @@ -1,13 +1,11 @@ 'use strict'; // Flags: --expose-gc // just like test-gc-http-client.js, -// but with an on('error') handler that does nothing. +// but with an on('error') handler that rethrows. const common = require('../common'); const { onGC } = require('../common/gc'); -const cpus = require('os').availableParallelism(); - function serverHandler(req, res) { req.resume(); res.writeHead(200, { 'Content-Type': 'text/plain' }); @@ -15,23 +13,23 @@ function serverHandler(req, res) { } const http = require('http'); -const numRequests = 36; -let createClients = true; -let done = 0; +// Keep the number of in-flight requests small and fixed. Opening too many +// connections at once can overflow the listen queue (capped at 128 on macOS), +// and the kernel then resets connections that are still being established. +const concurrency = 8; +const numRequests = 64; let count = 0; +let done = 0; let countGC = 0; const server = http.createServer(serverHandler); server.listen(0, common.mustCall(() => { - for (let i = 0; i < cpus; i++) - getAll(numRequests); + for (let i = 0; i < concurrency; i++) + getNext(); })); -function getAll(requestsRemaining) { - if (!createClients) - return; - - if (requestsRemaining <= 0) +function getNext() { + if (count >= numRequests) return; const req = http.get({ @@ -42,13 +40,14 @@ function getAll(requestsRemaining) { count++; onGC(req, { ongc }); - - setImmediate(getAll, requestsRemaining - 1); } function cb(res) { res.resume(); - done++; + res.on('end', () => { + done++; + getNext(); + }); } function onerror(err) { @@ -62,16 +61,14 @@ function ongc() { setImmediate(status); function status() { - if (done > 0) { - createClients = false; + if (done === numRequests) { global.gc(); - console.log(`done/collected/total: ${done}/${countGC}/${count}`); - if (countGC === count) { + console.log(`done/collected/total: ${done}/${countGC}/${numRequests}`); + if (countGC === numRequests) { server.close(); - } else { - setImmediate(status); + return; } - } else { - setImmediate(status); } + + setImmediate(status); } diff --git a/test/sequential/test-gc-http-client.js b/test/sequential/test-gc-http-client.js index 6b2a5fc03afb..56a6fff1b39b 100644 --- a/test/sequential/test-gc-http-client.js +++ b/test/sequential/test-gc-http-client.js @@ -5,31 +5,29 @@ const common = require('../common'); const { onGC } = require('../common/gc'); -const cpus = require('os').availableParallelism(); - function serverHandler(req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World\n'); } const http = require('http'); -const numRequests = 36; -let createClients = true; -let done = 0; +// Keep the number of in-flight requests small and fixed. Opening too many +// connections at once can overflow the listen queue (capped at 128 on macOS), +// and the kernel then resets connections that are still being established. +const concurrency = 8; +const numRequests = 64; let count = 0; +let done = 0; let countGC = 0; const server = http.createServer(serverHandler); server.listen(0, common.mustCall(() => { - for (let i = 0; i < cpus; i++) - getAll(numRequests); + for (let i = 0; i < concurrency; i++) + getNext(); })); -function getAll(requestsRemaining) { - if (!createClients) - return; - - if (requestsRemaining <= 0) +function getNext() { + if (count >= numRequests) return; const req = http.get({ @@ -40,13 +38,14 @@ function getAll(requestsRemaining) { count++; onGC(req, { ongc }); - - setImmediate(getAll, requestsRemaining - 1); } function cb(res) { res.resume(); - done += 1; + res.on('end', () => { + done++; + getNext(); + }); } function ongc() { @@ -56,16 +55,14 @@ function ongc() { setImmediate(status); function status() { - if (done > 0) { - createClients = false; + if (done === numRequests) { global.gc(); - console.log(`done/collected/total: ${done}/${countGC}/${count}`); - if (countGC === count) { + console.log(`done/collected/total: ${done}/${countGC}/${numRequests}`); + if (countGC === numRequests) { server.close(); - } else { - setImmediate(status); + return; } - } else { - setImmediate(status); } + + setImmediate(status); }