We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version
$ go version go version go1.12.7 darwin/amd64
Yes, it reproduces with go 1.13.1
go env
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/on99/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/on99/.gvm/pkgsets/go1.12.7/global" GOPROXY="" GORACE="" GOROOT="/Users/on99/.gvm/gos/go1.12.7" GOTMPDIR="" GOTOOLDIR="/Users/on99/.gvm/gos/go1.12.7/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/18/tghhmy8j77bgv7c0p4zqgw440000gp/T/go-build762921926=/tmp/go-build -gno-record-gcc-switches -fno-common"
https://play.golang.org/p/mtyMTtDj5vj
I expect it returns true.
It returns false.
The text was updated successfully, but these errors were encountered:
I'm not too familiar with the rate limiting algorithm, but the bug seems to come from a floating-point imprecision.
First, Limiter.advance calls tokensFromDuration(1299999999), which computes
Limiter.advance
tokensFromDuration(1299999999)
1.299999999 * 0.7692307692307693 = 0.9999999992307692 (current) 1.299999999 * 0.7692307692307693 = 0.9999999992307693207692307 (actual)
1.299999999 * 0.7692307692307693 = 0.9999999992307692
1.299999999 * 0.7692307692307693 = 0.9999999992307693207692307
That result (after subtracting n on line 320, which is 1) then skews durationFromTokens
n
durationFromTokens
(7.692307901763229e-10 / 0.7692307692307693)*1e9 = 1.0000000272292198 (current) (7.692306792307693e-10 / 0.7692307692307693)*1e9 = 0.9999998830000000000000105300000000 (actual)
(7.692307901763229e-10 / 0.7692307692307693)*1e9 = 1.0000000272292198
(7.692306792307693e-10 / 0.7692307692307693)*1e9 = 0.9999998830000000000000105300000000
Since that result is truncated (converted to an int64), the comparison on line 329 evaluates to false since waitDuration (1) <= maxFutureReserve (0).
int64
waitDuration (1) <= maxFutureReserve (0)
Manually fixing the inaccuracy inside tokensFromDuration fixes the bug.
tokensFromDuration
Sorry, something went wrong.
Change https://golang.org/cl/200917 mentions this issue: rate: fix truncated seconds in tokensFromDuration
rate: fix truncated seconds in tokensFromDuration
@ericlagergren Thank you, I got it.
Change https://golang.org/cl/200900 mentions this issue: rate: fix rounding error in tokensFromDuration
rate: fix rounding error in tokensFromDuration
golang/time@6d3f0bb
Successfully merging a pull request may close this issue.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, it reproduces with go 1.13.1
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/mtyMTtDj5vj
What did you expect to see?
I expect it returns true.
What did you see instead?
It returns false.
The text was updated successfully, but these errors were encountered: