Skip to content

Fix deadlock in race condition#294

Merged
AArnott merged 1 commit into
microsoft:mainfrom
AArnott:fixDeadlock
Jan 31, 2022
Merged

Fix deadlock in race condition#294
AArnott merged 1 commit into
microsoft:mainfrom
AArnott:fixDeadlock

Conversation

@AArnott
Copy link
Copy Markdown
Member

@AArnott AArnott commented Jan 31, 2022

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.

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.
@AArnott AArnott added the bug label Jan 31, 2022
@AArnott AArnott added this to the v17.2 milestone Jan 31, 2022
@AArnott
Copy link
Copy Markdown
Member Author

AArnott commented Jan 31, 2022

This fixes devdiv-1357805.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 31, 2022

Codecov Report

Merging #294 (db1c9fd) into main (59feab4) will decrease coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
...crosoft.VisualStudio.Composition/ExportProvider.cs 96.39% <100.00%> (-0.01%) ⬇️
...alStudio.Composition.Analyzers/Strings.Designer.cs 0.00% <0.00%> (-54.55%) ⬇️
...sualStudio.Composition/ComposablePartDefinition.cs 95.34% <0.00%> (-3.02%) ⬇️
...mposition/Configuration/AttributedPartDiscovery.cs 96.11% <0.00%> (-0.71%) ⬇️
...position/Configuration/SerializationContextBase.cs 94.10% <0.00%> (-0.41%) ⬇️
...oft.VisualStudio.Composition/RuntimeComposition.cs 92.42% <0.00%> (-0.03%) ⬇️
...timeExportProviderFactory+RuntimeExportProvider.cs 97.74% <0.00%> (+<0.01%) ⬆️
...sualStudio.Composition/CompositionConfiguration.cs 94.05% <0.00%> (+0.32%) ⬆️
...osoft.VisualStudio.Composition/Strings.Designer.cs 68.67% <0.00%> (+0.38%) ⬆️
...Microsoft.VisualStudio.Composition/ComposedPart.cs 96.92% <0.00%> (+0.52%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b01962...db1c9fd. Read the comment docs.

@AArnott AArnott merged commit 6547175 into microsoft:main Jan 31, 2022
@AArnott AArnott deleted the fixDeadlock branch January 31, 2022 17:30
AArnott added a commit that referenced this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants