Fix deadlock in race condition#294
Merged
Merged
Conversation
Ryan Molden analyzed a deadlock and the docs for `Monitor.Wait` and found that our call that includes a timeout means when the other lock holder takes more than 3 seconds to do its work and call `Monitor.PulseAll` that we'll still get `false` from `Monitor.Wait`. Then when we loop around to `Monitor.Wait` again, it will block for a `PulseAll` that may never recur. The fix is to double-check the state before re-entering the Wait to see if we just missed the `PulseAll` call. If we did, we break out of the loop immediately. I also add more to another code comment discussing thread concerns to make it clearer that it's doing what it is supposed to.
Member
Author
|
This fixes devdiv-1357805. |
Codecov Report
@@ Coverage Diff @@
## main #294 +/- ##
==========================================
- Coverage 89.62% 89.55% -0.07%
==========================================
Files 87 87
Lines 6053 6111 +58
==========================================
+ Hits 5425 5473 +48
- Misses 628 638 +10
Continue to review full report at Codecov.
|
ryanmolden
approved these changes
Jan 31, 2022
milopezc
approved these changes
Jan 31, 2022
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ryan Molden analyzed a deadlock and the docs for
Monitor.Waitand found that our call that includes a timeout means when the other lock holder takes more than 3 seconds to do its work and callMonitor.PulseAllthat we'll still getfalsefromMonitor.Wait. Then when we loop around toMonitor.Waitagain, it will block for aPulseAllthat may never recur.The fix is to double-check the state before re-entering the Wait to see if we just missed the
PulseAllcall. If we did, we break out of the loop immediately.I also add more to another code comment discussing thread concerns to make it clearer that it's doing what it is supposed to.