-
Notifications
You must be signed in to change notification settings - Fork 18k
x/time/rate: NewLimiter with burst of 1 and rate of 0 always allows #39984
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
Comments
I think what happens is that As the time needed to refill the bucket is, in this particular case, negative, this then evaluates to true: https://github.com/golang/time/blob/master/rate/rate.go#L335 |
This isn't a zero valued Limiter. |
I agree that the first call to function I sent a PR, please feel free to check it. |
The line number in @akolar's comments are out of date, so here's fixed links (using a constant commit). Old: https://github.com/golang/time/blob/master/rate/rate.go#L391
Old: https://github.com/golang/time/blob/master/rate/rate.go#L335
|
i want get someone's help to review my change about this issue: https://go-review.googlesource.com/c/time/+/323429 please feel free to review it |
Change https://golang.org/cl/323429 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
See https://play.golang.org/p/u6Hygbausg7
What did you expect to see?
I expected the first call to
r.Allow()
to return true and the second call to return false.I expect this based on the following docs:
and
So
NewLimiter
should create a full bucket of size 1 that never refills and each call toAllow
should consume one token from the bucket.What did you see instead?
Instead it appears that calls to
Allow
never consume a token and always return true.The text was updated successfully, but these errors were encountered: