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: alternating AllowN before last and after last can create new tokens #56287
Comments
@bcmills , @ianlancetaylor can you give this a look? |
|
I think this is work as designed. It's covered by the test In your demo, every time it jumps from t1 to t0, it gets two new tokens. That's why the available tokens never reduce to 0. By the way, @tentree please change your comment to put your code into a fenced code block: ```go package main import ( "fmt" "time" "golang.org/x/time/rate" ) func main() { limiter := rate.NewLimiter(1, 10) t0 := time.Now() t1 := time.Now().Add(-time.Second * 2) t := t0 for limiter.AllowN(t, 1) { if t == t0 { t = t1 } else { t = t0 } } fmt.Println("exit") } ``` |
since |
@tentree Please don't quote an entire comment unnecessarily (edit your comment to remove it). Jumping backward won't reduce the tokens. It's also covered by that same test (line 127, |
@ZekeLu thanks , i may understand the designe of limiter. back in the past just like fixed clock. the func with |
In my opinion, the Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. Please close this issue if there is not bug. See https://github.com/golang/go/wiki/Questions. |
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?
What did you expect to see?
Exit loop
What did you see instead?
Always loop.
mark:
i also use the fixed(ZekeLu/time@127e7a4) of #52584, but it did not work.
The text was updated successfully, but these errors were encountered: