-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Milestone
Description
People sometimes build their own time.Ticker values in order to inject a time.Ticker value into some other function. This lets them control when values are sent on the channel, in order to write tests that work more quickly.
Whether we think this is a good strategy or not, it did work with 1.9. It fails on current tip. Sample program:
package main
import "time"
func main() {
c := make(chan time.Time)
t := &time.Ticker{C: c}
t.Stop()
}
Running this program crashes:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x43c2ee]
goroutine 1 [running]:
time.stopTimer(0xc420062008, 0xc420062000)
/home/iant/go/src/runtime/time.go:117 +0x2b
time.(*Ticker).Stop(0xc420062000)
/home/iant/go/src/time/tick.go:46 +0x31
main.main()
foo.go:8 +0x74
exit status 2
It should be possible to fix this to avoid breaking people's programs unnecessarily.
CC @valyala