Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Go race with Mock #44

Closed
stevedalton opened this issue Mar 3, 2022 · 1 comment · Fixed by #54
Closed

Go race with Mock #44

stevedalton opened this issue Mar 3, 2022 · 1 comment · Fixed by #54
Assignees

Comments

@stevedalton
Copy link

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 removeClockTimer sorts the timers while holding the mutex. The sort method calls Next(), which reads the internal next field.
  • The internal method runNextTimer calls Tick on the timer without holding the mutex, and Tick sets the internal next field of the timer.

It seems that solving this might just require removing the sort.Sort call in removeClockTimer.

@djmitche
Copy link
Collaborator

Removing the sort would still leave runNextTimer modifying things without protection, so that's not a good fix.

@djmitche djmitche linked a pull request Apr 23, 2023 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants