]> Cypherpunks repositories - gostls13.git/commit
runtime: return deltimer early if timer.timersBucket is unset
authorEmmanuel Odeke <emm.odeke@gmail.com>
Fri, 15 Sep 2017 01:12:26 +0000 (19:12 -0600)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Fri, 15 Sep 2017 19:55:10 +0000 (19:55 +0000)
commita72e26f246a50b2d5226262420874b143d9d8b5a
tree72c5bead618af9c14d890865d031e0350b66dcde
parent37fc70bac3a02e38859a09996e7ea95c3c64aed4
runtime: return deltimer early if timer.timersBucket is unset

Return early from deltimer, with false as the result,
to indicate that we couldn't delete the timer since its
timersBucket was nil(not set) in the first place.

That happens in such a case where a user created
the timer from a Ticker with:

  t := time.Ticker{C: c}

The above usage skips the entire setup of assigning
the appropriate underlying runtimeTimer and timersBucket,
steps that are done for us by time.NewTicker.

CL 34784 introduced this bug with an optimization, by changing
stopTimer to retrieve the timersBucket from the timer itself
(which is unset with the mentioned usage pattern above),
whereas the old  behavior relied on indexing
by goroutine ID into the global slice of runtime
timers, to retrieve the appropriate timersBucket.

Fixes #21874

Change-Id: Ie9ccc6bdee685414b2430dc4aa74ef618cea2b33
Reviewed-on: https://go-review.googlesource.com/63970
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/time.go
src/time/tick_test.go