Skip to content

Commit 4fd8c28

Browse files
authored
Fix: Handle backoffLimit being undefined (#796)
1 parent d8d6cfe commit 4fd8c28

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

source/core/Ky.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ export class Ky {
297297
}
298298
}
299299

300-
return Math.min(this.#options.retry.backoffLimit, jitteredDelay);
300+
// Handle undefined backoffLimit by treating it as no limit (Infinity)
301+
const backoffLimit = this.#options.retry.backoffLimit ?? Number.POSITIVE_INFINITY;
302+
return Math.min(backoffLimit, jitteredDelay);
301303
}
302304

303305
async #calculateRetryDelay(error: unknown) {

test/retry.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,41 @@ test('respect maximum backoffLimit', async t => {
631631
await server.close();
632632
});
633633

634+
test('backoffLimit: undefined treats as no limit (Infinity)', async t => {
635+
const retryCount = 4;
636+
let requestCount = 0;
637+
638+
const server = await createHttpTestServer();
639+
server.get('/', (_request, response) => {
640+
requestCount++;
641+
642+
if (requestCount === retryCount + 1) {
643+
response.end(fixture);
644+
} else {
645+
response.sendStatus(500);
646+
}
647+
});
648+
649+
// When backoffLimit is undefined, it should behave the same as no limit
650+
// (i.e., delays should not be clamped, same as default behavior)
651+
await withPerformance({
652+
t,
653+
expectedDuration: 300 + 600 + 1200 + 2400,
654+
async test() {
655+
t.is(await ky(server.url, {
656+
retry: {
657+
limit: retryCount,
658+
backoffLimit: undefined,
659+
},
660+
}).text(), fixture);
661+
},
662+
});
663+
664+
t.is(requestCount, 5);
665+
666+
await server.close();
667+
});
668+
634669
test('respect custom retry.delay', async t => {
635670
const retryCount = 4;
636671
let requestCount = 0;

0 commit comments

Comments
 (0)