-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lock races in the controller engine
In a bunch of places I was: 1. Taking a read lock, reading state, releasing the read lock. 2. Computing something based on the read state. 3. Taking a write lock and using the computation to mutate the state. The issue with this approach is that Goroutine B can take the write lock and mutate state between when Goroutine A reads state and when it writes new state based on what it read. Goroutine A is operating on stale state. I think there's some benefit in using an RWMutex to avoid blocking everyone when there's no work to do, but a better approach is to: 1. Take the read lock, figure out what work needs to be done, release the read lock and return early if there's no work to be done. 2. If there's work to be done, take the write lock, figure out again what work there is to be done, and do it. Signed-off-by: Nic Cope <nicc@rk0n.org>
- Loading branch information
Showing
1 changed file
with
62 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters