-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(waiter): use a buffered channel to fix race condition
We discovered a race condition in where `Waiter.Set` and `Waiter.Next` could both be called once, but `Waiter.Next` would never resolve with the result. The reason for this is that `sync.Cond` does not appear to retain any kind of state, so if `w.c.Broadcast` is called first, `w.c.Wait` does not know that it can continue. By using a buffered channel instead we can get around that issue. According to the benchmark tests this is actually faster too: decreasing the ops per ns from ~200 to ~150. Signed-off-by: Matthew Kocher <mkocher@vmware.com> Co-authored-by: Matthew Kocher <mkocher@vmware.com>
- Loading branch information
Showing
2 changed files
with
64 additions
and
58 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
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