Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place a floor of 1 on the rate limit burst to prevent x/time from throwing an error #1837

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

marwatk
Copy link
Contributor

@marwatk marwatk commented Nov 13, 2023

If GitLab is enforcing rate limits of fewer than 3 per second the existing logic will set burst to zero (it multiplies the per-second value by 0.33 and then casts to int).

rate.Limiter.Wait will fail if burst is zero because Wait falls back to WaitN with n=1:

…owing 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
Copy link
Member

@svanharmelen svanharmelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @marwatk 👍🏻

@svanharmelen svanharmelen merged commit 3e35f87 into xanzy:main Nov 15, 2023
3 checks passed
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.

2 participants