Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit a449e2b

Browse files
committed
Place a floor of 1 on the rate limit burst to prevent x/time from throwing an error.
If GitLab is enforcing rate limits of fewer than 3 per second the existing logic will set burst to zero (it multiples the per-second value by 0.33 and then casts to int). rate.Limiter.Wait will fail if burst is zero with the message here: https://github.com/golang/time/blob/b24d3b5e50f7b0e18486d18f0a240d04d254ea73/rate/rate.go#L257 As Wait falls back to WaitN with n=1: https://github.com/golang/time/blob/b24d3b5e50f7b0e18486d18f0a240d04d254ea73/rate/rate.go#L231
1 parent 793bc3c commit a449e2b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ func (c *Client) configureLimiter(ctx context.Context, headers http.Header) {
533533
limit := rate.Limit(rateLimit * 0.66)
534534
burst := int(rateLimit * 0.33)
535535

536+
// Need at least one allowed to burst or x/time will throw an error
537+
if burst == 0 {
538+
burst = 1
539+
}
540+
536541
// Create a new limiter using the calculated values.
537542
c.limiter = rate.NewLimiter(limit, burst)
538543

0 commit comments

Comments
 (0)