x/time/rate: Impossible to use reservation delay #57429
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
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?
Playground: https://go.dev/play/p/HLAZYj9BGhx
I was trying to use the
rate.(*Limiter).Reserve()
to control backpressure andrate.(*Reservation).Delay()
to fill aRetry-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 aRetry-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.
The text was updated successfully, but these errors were encountered: