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 <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67607
Refs: https://github.com/nodejs/node/issues/41399
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
Reviewed-By: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
This commit is contained in:
Matteo Collina authored and Antoine du Hamel committed 2026-11-25 18:00:46 +01:00
1 parent f99cbb36ea
commit 1b2ee6fc2f
2 files changed
+41 -47

No files matched your search

+21 -24
View File
@@ -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);
}
+20 -23
View File
@@ -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);
}