Commit 06250cba58e for nodejs

commit 06250cba58ed8c94ecbe100d88a1fb695245602b
Author: Matteo Collina <hello@matteocollina.com>
Date:   Sat Nov 21 11:54:19 2026 +0100

    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>

diff --git a/test/sequential/test-gc-http-client-onerror.js b/test/sequential/test-gc-http-client-onerror.js
index 1c311c6a9b6..b498f3c7733 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 6b2a5fc03af..56a6fff1b39 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);
 }