Bug: Exponential backoff delay uses wrong time unit (seconds instead of milliseconds)
## Description
The `defaultRequestHandler` in `@gitbeaker/rest` has a bug in its exponential backoff retry logic. The delay calculation produces values intended to be seconds, but `setTimeout` expects milliseconds.
## Current Behavior
In `packages/rest/src/Requester.ts`, the retry delay is calculated as:
```typescript
await delay(2 ** i * 0.25);
```
This produces delays of: `0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128`
Since `setTimeout` expects milliseconds, these values are effectively:
- 0ms, 0ms, 1ms, 2ms, 4ms, 8ms, 16ms, 32ms, 64ms, 128ms
**Total wait time across 10 retries: ~256 milliseconds**
This means when hitting a 429 rate limit, all 10 retries execute almost instantly (~256ms total), which defeats the purpose of exponential backoff.
## Expected Behavior
The delays should be in milliseconds for meaningful backoff:
- 250ms, 500ms, 1000ms, 2000ms, 4000ms, 8000ms, 16000ms, 32000ms, 64000ms, 128000ms
**Total wait time: ~256 seconds (~4.3 minutes)**
## Suggested Fix
Change line 98 in `packages/rest/src/Requester.ts` from:
```typescript
await delay(2 ** i * 0.25);
```
To:
```typescript
await delay(2 ** i * 250);
```
## Environment
- `@gitbeaker/rest` version: 41.3.0
- Node.js version: 20.x
## Reproduction
1. Make requests to GitLab API that trigger rate limiting (429 responses)
2. Observe that all 10 retries complete in under 1 second
3. Final error: `GitbeakerRetryError: Could not successfully complete this request after 10 retries, last status code: 429`
## Workaround
Using `patch-package` to fix locally:
```diff
- await delay(2 ** i * 0.25);
+ await delay(2 ** i * 250);
```
0 条评论