-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix incorrect usage of time.Timer
#45839
Conversation
Calling `timer.Stop` in a timer that already fired results in `Stop` returning false and subsequent drain will block because the channel isn't closed. This PR fixes the drain behaviour by wrapping the drain operation in a non-blocking select.
b35843f
to
aec8ede
Compare
timer.Timer
time.Timer
Does this change still hold for Go 1.23, or do we need to leave a note to go back and update?
|
Unfortunately, Go 1.23 won't fix this situation directly check. Although it doesn't fix the problem, Go 1.23 removed the misleading example where I got this incorrect behavior. check the discussion golang/go#27169 |
Invoking
timer.Stop
on a timer that has already fired causesStop
to return false, and any subsequent drain operation will block because the channel remains open.This PR addresses the blocking issue by wrapping the drain operation in a non-blocking select.