clock
clock copied to clipboard
Go race with Mock
I believe the following demonstrates the issue:
c := clock.NewMock()
go c.Ticker(time.Second).Stop()
c.Add(time.Second)
Unfortunately, it's hard to get Go's race detector to catch this (I only ran it across it in a more complicated case by accident).
The detailed problem is as follows:
- The internal method
removeClockTimersorts the timers while holding the mutex. The sort method callsNext(), which reads the internalnextfield. - The internal method
runNextTimercallsTickon the timer without holding the mutex, andTicksets the internalnextfield of the timer.
It seems that solving this might just require removing the sort.Sort call in removeClockTimer.