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

x/time/rate: Impossible to use reservation delay #57429

Closed
geovanisouza92 opened this issue Dec 21, 2022 · 5 comments
Closed

x/time/rate: Impossible to use reservation delay #57429

geovanisouza92 opened this issue Dec 21, 2022 · 5 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@geovanisouza92
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.19.3 darwin/arm64

Does this issue reproduce with the latest release?

✅ Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/geovani/Library/Caches/go-build"
GOENV="/Users/geovani/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/geovani/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/geovani/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.3/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/63/nh001khd1792rxsfl5qbzmt40000gn/T/go-build3264002040=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Playground: https://go.dev/play/p/HLAZYj9BGhx

I was trying to use the rate.(*Limiter).Reserve() to control backpressure and rate.(*Reservation).Delay() to fill a Retry-After http header instead blocking the goroutine.

What did you expect to see?

Nothing in the playground logs.

In my code I was expecting (*Reservation).OK() return false and (*Reservation).Delay() return the amount of time we need to wait to reserve more tokens, allowing to use this value to fill a Retry-After http header, for example.

What did you see instead?

"should not reserve" logged in the playground, while in my code (*Reservation).OK() returns true. Trying to use (*Reservation).Delay() will block the goroutine forever.


Not sure the authors intention, but it seems that if we change the maxDuration (or at least expose it as a param) in this line the code will be able to meet the requirement and documented behavior.

I like the package concept and hope it get promoted to the stdlib with a simpler interface.

@gopherbot gopherbot added this to the Unreleased milestone Dec 21, 2022
@dr2chase
Copy link
Contributor

@rsc not sure who else to suggest look at this.

@ianlancetaylor
Copy link
Contributor

CC @Sajmani

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 22, 2022
@seankhliao
Copy link
Member

I believe this is working as intended? https://go.dev/play/p/6ccCWLVKJzJ
OK() returns true because it's possible to provide tokens at some point in the future, Delay() works as expected.

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Dec 24, 2022
@Sajmani
Copy link
Contributor

Sajmani commented Jan 4, 2023

@seankhliao is correct. The reservation returns OK because it's possible to act within the rate limit after waiting the delay. It only returns !OK if there's no amount of time you can wait to act within the rate limit.

@Sajmani Sajmani closed this as completed Jan 4, 2023
@geovanisouza92
Copy link
Author

@Sajmani @seankhliao Thanks for investigating this 🙏

So, your suggestion it to completely ignore .OK() and check .Delay() == time.Duration(0) to know its allowed to proceed?

@golang golang locked and limited conversation to collaborators Jan 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants