-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
x/time/rate: Zero limiter allows events #18763
Comments
What's the behavior of this on Go1.7? |
Given the issue cropped up on our android app, which is built using 1.7.x, I'd say the same. |
Seems like the behavior is consistent with the documentation. |
In that case, the generic behaviour is not consistent ccompared to arm64, which goes back to the original compiler issue I've opened. |
The real quote is on the Limit type, which says a zero rate allows no events. (On mobile, so not pasting) |
The docs say:
NewLimiter always returns a non-zero limiter, regardless of its arguments. Let's close this bug but we can keep #18762 open for the floating point arm/arm64 issue. |
@bradfitz There does seem to be an inconsistency since (or at least ambiguity), as @calmh pointed out, https://godoc.org/golang.org/x/time/rate#Limit says |
(I wrote a comment about how this should not have been closed, but the corresponding issue now lives in #18762 instead so this is fine. I'll go away now.) |
Okay, reopening. I didn't see there were two parts of the docs talking about zero values. |
@bradfitz Here is the doc talking about zero limiter https://github.com/golang/time/blob/master/rate/rate.go#L39 I am running into the same issue. If my limit is 0 (burst size is 1), I want my burst size to be non zero because I want threads to block on Wait() and not return error. |
like @madhuravi mentioned, the behavior is surprising to me that Wait on limit 0 burst 1 is not giving error or waiting |
As the documentation of
The expected behavior is not allowed, here's a more detailed test: package main
import "time"
func main() {
limiter := NewLimiter(0, 1)
limiter.AllowN(time.Now(), 1)
for i := 0; i < 10000; i++ {
allow := limiter.AllowN(time.Now(), 1)
if allow {
panic("should not happen")
}
}
} |
And this has been fixed in Use the latest version could solve this issue, for example:
Or here's a workaround for this issue: limiter := NewLimiter(math.SmallestNonzeroFloat64, 1) |
Neither of the following has taken effect when call
But the following is in effect, the call to
|
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Run the following on amd64:
What did you expect to see?
Output ok
What did you see instead?
Output broken, yet documentation says:
The zero value is a valid Limiter, but it will reject all events.
Please note this does work as documented on arm64 which I suspect is a compiler bug either in everything else apart from arm64 or a bug in arm64 and this library.
See #18762,
The text was updated successfully, but these errors were encountered: