From fa26fb4c037e3bd2d96a07683b6d4a653dfb47b1 Mon Sep 17 00:00:00 2001 From: Golo Roden Date: Fri, 20 Nov 2026 23:12:02 +0100 Subject: [PATCH] chore: Give every write a server of its own when fetch gives up connecting. Since undici 8.11, which Node.js bundles from 26.11 on, the pool of fetch opens one connection per origin at a time and lets further requests wait. When that connection never completes its TLS handshake, the waiting requests get their turn one after another, so four writes against one server gave up after 10, 21, 31 and 42 seconds, and the test ran into its 20-second limit with Node.js 26.13.1 (#450). Each write now has a test and a server of its own, and the suite leaves room for four of them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FzFci9EsPi8wnfncwsRgg8 --- src/writeBeforeSending.test.ts | 57 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/writeBeforeSending.test.ts b/src/writeBeforeSending.test.ts index cb6474f..f881224 100644 --- a/src/writeBeforeSending.test.ts +++ b/src/writeBeforeSending.test.ts @@ -58,8 +58,9 @@ const isAbortError = (error: unknown): boolean => // however it fails, so it fails with the error itself. The server accepts the // connection, but never answers the TLS handshake, so the request never gets // beyond establishing the connection. -// biome-ignore lint/nursery/noExcessiveStatementsPerFunction: A suite counts each of its tests as a statement. -suite('a write that fails before its request went out', { timeout: 30_000 }, () => { +// Four of its tests wait ten seconds each for fetch to give up connecting, so +// the timeout of the suite has to leave room for all of them. +suite('a write that fails before its request went out', { timeout: 60_000 }, () => { let server: net.Server; let sockets: net.Socket[]; let url: URL; @@ -129,6 +130,30 @@ suite('a write that fails before its request went out', { timeout: 30_000 }, () error.cause.code === 'UND_ERR_HEADERS_TIMEOUT', ); }); + + // The fetch built into Node.js gives up connecting after 10 seconds. Its + // pool opens one connection per origin at a time and lets further + // requests wait for it, so writes that share a server would give up one + // after another; each test has a server of its own. + test('throws the error of fetch itself if fetch gives up connecting.', { + timeout: 20_000, + }, async (): Promise => { + const transport = createTransport(apiVersion, { + url, + apiToken: 'secret', + stallTimeout: 30_000, + }); + + await assert.rejects( + run(transport), + (error: unknown): boolean => + error instanceof TypeError && + !(error instanceof ConnectionStalledError) && + error.cause instanceof Error && + 'code' in error.cause && + error.cause.code === 'UND_ERR_CONNECT_TIMEOUT', + ); + }); }); }; @@ -138,34 +163,6 @@ suite('a write that fails before its request went out', { timeout: 30_000 }, () } } - // The fetch built into Node.js gives up connecting after 10 seconds, so - // this runs every write at once. - test('throws the error of fetch itself if fetch gives up connecting.', { - timeout: 20_000, - }, async (): Promise => { - await Promise.all( - apiVersions.flatMap(apiVersion => - writes.map(async ({ run }): Promise => { - const transport = createTransport(apiVersion, { - url, - apiToken: 'secret', - stallTimeout: 30_000, - }); - - await assert.rejects( - run(transport), - (error: unknown): boolean => - error instanceof TypeError && - !(error instanceof ConnectionStalledError) && - error.cause instanceof Error && - 'code' in error.cause && - error.cause.code === 'UND_ERR_CONNECT_TIMEOUT', - ); - }), - ), - ); - }); - test('throws an unknown outcome if it cannot tell whether the request went out.', async (): Promise => { // A fetch that is not the one built into Node.js does not tell when the // headers of a request went out.