-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: cmd/vet: warn about copying a time.Timer value #69186
Comments
package main
import "time"
func main() {
illegalTimerCopy := *time.NewTimer(time.Second)
illegalTimerCopy.Stop() // block for ever
} |
I'm kind of surprised this ever worked. I don't think it would work in general cases. It might work in cases where you are careful to call |
Unless we get a lot of reports about breakage due to this, we aren't going to change it. So changing this to a proposal for a vet check. Though I don't know how useful a vet check would be--I don't know how often this occurs. At least since Go 1.4 the
That doc was added for #8776. So I think this has always been documented as not working. |
If we do decide to add it to vet, copylock is a natural home for implementing this (if a mildly inappropriate name). |
Just my 2 cents on this: in a real code base this can lead to a crash that doesn't trivially show the root cause. And the exact same code did work in go 1.22, so in my opinion something should be done about this, because technically this is a breaking change. The linked documentation
doesn't mention that after creation you cannot copy the timer's value. |
Unless we get a lot of reports about breakage due to this, we aren't going to change it. |
The following code works fine on Go 1.22, but breaks on Go 1.23.0 on the
http.DefaultClient.Do()
line. On Linux, it freezes the entire runtime and never continues. On macOS, it throws afatal error: ts set in timer
It's presumably somehow caused by the Go 1.23 timer changes, but I'm not sure how exactly, so I don't know if it's a bug or a feature. Assuming it's not a bug, it would be nice if
go vet
could report that similar to the mutex copy warnings.The text was updated successfully, but these errors were encountered: