From b2085f98f916692ba2beca0a6a4ac18fe6651404 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Sun, 1 Feb 2026 22:49:11 +0000 Subject: [PATCH] fix: Add explicit `ETIMEDOUT` when connection doesn't establish with headers (#24) --- .changeset/gold-impalas-think.md | 5 +++++ src/fetch.ts | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changeset/gold-impalas-think.md diff --git a/.changeset/gold-impalas-think.md b/.changeset/gold-impalas-think.md new file mode 100644 index 0000000..5fb2ec8 --- /dev/null +++ b/.changeset/gold-impalas-think.md @@ -0,0 +1,5 @@ +--- +'fetch-nodeshim': patch +--- + +Issue an explicit `ETIMEDOUT` when the request times out diff --git a/src/fetch.ts b/src/fetch.ts index 2825bbd..338b506 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -160,6 +160,14 @@ async function _fetch( signal?.addEventListener('abort', destroy); + outgoing.on('timeout', () => { + if (!incoming) { + const error = new Error('Request timed out') as NodeJS.ErrnoException; + error.code = 'ETIMEDOUT'; + destroy(error); + } + }); + outgoing.on('response', _incoming => { if (signal?.aborted) { return; -- 2.51.2