-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
time timer.Reset is not thread safe #26741
Comments
Dup of #25686, fixed on tip (to be 1.11), your snippet now crashes with:
|
Ok, I don't understand the relationship between the timer.Reset panicking and inability to use its return value in sensible way. The docs say:
The docs don't say that the runtime will panic if you call timer.Reset from two goroutines. Perhaps I'l explain my use case:
Right now the semantics of timer.Reset seem to focus on documenting (A) while ignoring the way more common pattern (B). To get (B) working I need to... dunno... have a lock around timer.Reset()? This is pretty insane. |
Can you open a new issue? This one was about the panic and I think we fixed that. I don't understand if you're asking for a doc change, a behaviour change, or both. I also don't understand the connection between the bad-looking panic you reported initially and your second post. In the new issue, please explain clearly what kind of change you're asking for. Thanks. |
Yes, I am aware that timer.Reset is impossible to be used correctly. This bug is not about timer.Reset semantics, it's about panic it causes.
What version of Go are you using (
go version
)?The bug happens in 1.10. The bug doesn't happen in 1.9.7
Does this issue reproduce with the latest release?
Haven't tried. Looking at code I'd say - yes.
What did you do?
What did you expect to see?
Not a panic.
What did you see instead?
A panic
Explanation
timer.Reset goes into
addtimer
https://github.com/golang/go/blob/go1.10/src/runtime/time.go#L128-L133
See that t.assignBucket is called outside of lock. My understanding is that the result of
assignBucket
depends based on current thread. Therefore we can end up in timer being assigned to differenttb
if they were called concurrently.This isn't a problem itself, but then
addTimerLocked
sets t.i:which of course makes no sense if it's done by diffent buckets. Therefore golang crashes with index error.
The text was updated successfully, but these errors were encountered: