Skip to content

Conversation

@adickinson72
Copy link

Summary

The delay calculation 2 ** i * 0.25 produces values that are effectively sub-millisecond (0.25ms, 0.5ms, 1ms...) when passed to setTimeout, which expects milliseconds. This causes all 10 retries to complete in ~256ms instead of the intended ~256 seconds of exponential backoff.

Changes

  • Changed await delay(2 ** i * 0.25) to await delay(2 ** i * 250) in packages/rest/src/Requester.ts
  • Updated the retry test to use Jest fake timers since delays are now significant

New Delay Schedule

Retry Old (ms) New (ms)
0 0.25 250
1 0.5 500
2 1 1,000
3 2 2,000
4 4 4,000
5 8 8,000
6 16 16,000
7 32 32,000
8 64 64,000
9 128 128,000
Total ~256ms ~256s (~4.3min)

Testing

  • All unit tests pass
  • Linting passes
  • The retry test now uses jest.useFakeTimers() and jest.runAllTimersAsync() to avoid actual waiting

Fixes #3805

…onds

The delay calculation `2 ** i * 0.25` produces values that are effectively
sub-millisecond (0.25ms, 0.5ms, 1ms...) when passed to setTimeout, which
expects milliseconds. This causes all 10 retries to complete in ~256ms
instead of the intended ~256 seconds of exponential backoff.

Changed to `2 ** i * 250` to produce proper millisecond delays:
- Retry 0: 250ms
- Retry 1: 500ms
- Retry 2: 1000ms (1s)
- ...
- Retry 9: 128000ms (128s)

This ensures meaningful backoff when hitting 429 rate limits or 502 errors.

Also updated the test to use fake timers since the delays are now significant.

Fixes jdalrymple#3805
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Exponential backoff delay uses wrong time unit (seconds instead of milliseconds)

1 participant