From 8b8c869f04469006dc8f1e5539ad9d5f55a13476 Mon Sep 17 00:00:00 2001 From: Tim Kelty Date: Fri, 28 Aug 2026 07:09:57 -0400 Subject: [PATCH] Retry HTTP 408 responses --- dist/aws4fetch.cjs.js | 2 +- dist/aws4fetch.esm.js | 2 +- dist/aws4fetch.esm.mjs | 2 +- dist/aws4fetch.umd.js | 2 +- src/main.js | 2 +- test/paramTests.js | 12 ++++++++++++ 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dist/aws4fetch.cjs.js b/dist/aws4fetch.cjs.js index b827565..84fabef 100644 --- a/dist/aws4fetch.cjs.js +++ b/dist/aws4fetch.cjs.js @@ -71,7 +71,7 @@ class AwsClient { return fetched } const res = await fetched; - if (res.status < 500 && res.status !== 429) { + if (res.status < 500 && res.status !== 429 && res.status !== 408) { return res } await new Promise(resolve => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))); diff --git a/dist/aws4fetch.esm.js b/dist/aws4fetch.esm.js index 9c27de4..b2078e8 100644 --- a/dist/aws4fetch.esm.js +++ b/dist/aws4fetch.esm.js @@ -67,7 +67,7 @@ class AwsClient { return fetched } const res = await fetched; - if (res.status < 500 && res.status !== 429) { + if (res.status < 500 && res.status !== 429 && res.status !== 408) { return res } await new Promise(resolve => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))); diff --git a/dist/aws4fetch.esm.mjs b/dist/aws4fetch.esm.mjs index 9c27de4..b2078e8 100644 --- a/dist/aws4fetch.esm.mjs +++ b/dist/aws4fetch.esm.mjs @@ -67,7 +67,7 @@ class AwsClient { return fetched } const res = await fetched; - if (res.status < 500 && res.status !== 429) { + if (res.status < 500 && res.status !== 429 && res.status !== 408) { return res } await new Promise(resolve => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))); diff --git a/dist/aws4fetch.umd.js b/dist/aws4fetch.umd.js index 8fdb68f..da7253a 100644 --- a/dist/aws4fetch.umd.js +++ b/dist/aws4fetch.umd.js @@ -73,7 +73,7 @@ return fetched } const res = await fetched; - if (res.status < 500 && res.status !== 429) { + if (res.status < 500 && res.status !== 429 && res.status !== 408) { return res } await new Promise(resolve => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))); diff --git a/src/main.js b/src/main.js index ebc7212..cee229f 100644 --- a/src/main.js +++ b/src/main.js @@ -115,7 +115,7 @@ export class AwsClient { return fetched // No need to await if we're returning anyway } const res = await fetched - if (res.status < 500 && res.status !== 429) { + if (res.status < 500 && res.status !== 429 && res.status !== 408) { return res } await new Promise(resolve => setTimeout(resolve, Math.random() * this.initRetryMs * Math.pow(2, i))) diff --git a/test/paramTests.js b/test/paramTests.js index f4e5520..63ee08c 100644 --- a/test/paramTests.js +++ b/test/paramTests.js @@ -73,6 +73,18 @@ export default async() => { })).headers.get('authorization') assertEqual(authorization, 'AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/sqs/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=28cde03d679fcd9082587d2705ea318df3d61f4d5d7006668b039b66f06c750c') } + + const originalFetch = globalThis.fetch + let attempts = 0 + globalThis.fetch = async() => new Response(null, { status: ++attempts === 1 ? 408 : 200 }) + + try { + const response = await new AwsClient({ ...keys, retries: 1, initRetryMs: 1 }).fetch(url) + assertEqual(response.status, 200) + assertEqual(attempts, 2) + } finally { + globalThis.fetch = originalFetch + } } function assertEqual(actual, expected) {