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: Wait's behaviour is inconsistent when the limit is 0 (tested on darwin/arm64 and linux/amd64) #47817
Comments
I'd think the right behavior here would be to block forever, as on your machine. From the docs:
And Since we don't have any owners listed (https://dev.golang.org/owners) I'll pick some names from the blamelist: @Sajmani @josharian |
Actually, I think this is exactly #47221. The difference seen here can be explained by different divide-by-zero behavior on arm64 vs. amd64. |
Er, not divide by zero behavior, it might go deeper than that with |
@mknyszek So yeah, that panic I mentioned is just a panic I instantiated in https://play.golang.org/p/nPng8M23CEf (line 19).
Sorry for the confusion. Anyway, the error comes from Wait (rate limit is zero, and with context with a timeout, we will exceed its deadline no matter what). This is similar to passing the background context, but there's no blocking, as expected. For both examples, I'm not sure if this is the correct behaviour either because we need to take burst into account. |
I think I was able to pinpoint the problem, and now it's a matter of figuring out why
and why
When the limit is zero, there's this division by zero in I suspect conversion because I looked up the bytes of +Inf I tested on darwin/amd64 and darwin/arm64 with Go 1.17. If I knew where to look, I'm happy to work on this problem. |
In Go, when converting a floating-point value to an integer type, if the floating-point value can't be represented in the integer type, the result is implementation defined. Quoting https://golang.org/ref/spec#Conversions:
I think that what you are seeing here is that the amd64 and arm64 implementations produce different results when converting a floating-point infinity to an integer type. If it's important to handle this case similarly, the code needs to check for that case explicitly. (I have not looked at the code.) |
What version of Go are you using (
go version
)?and
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?
The following program will block forever on my machine: https://play.golang.org/p/STtqVhMulsy. On linux/amd64, it runs just fine. Similarly, this panics on my computer: https://play.golang.org/p/nPng8M23CEf.
What did you expect to see?
Consistent behaviour.
What did you see instead?
Inconsistent behaviour.
It might be closely related to #47221, but I'm not 100% sure.
The text was updated successfully, but these errors were encountered: