-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing the contention condition caused by RegisterResolversManifests #11079
Conversation
532900a
to
2cdfbf7
Compare
2cdfbf7
to
d7826cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few minor comments; man one moving away from using the thread class
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Rainer Sigwald <[email protected]>
…et/msbuild into SdkResolverService_race_fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First quick pass.
There is lots of test related code in production code - can we isolate it inot tests
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for making the efforts to clean the production part of the code! I like this!!
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs
Outdated
Show resolved
Hide resolved
GitHub did not automatically close #7927. See "Multiple issues" in https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword. |
Fixes #11043, #7927
Context
There was a contention condition described here:
One thread enters and locks, then initializes a list, starts pushing things onto the list, which is now no longer null.
Second thread then checks, sees the list is not empty and bypasses the lock, acquires enumerator.
First thread pushes additional item into the list.
Second thread throws.
Changes Made
Initializing the list to a placeholder first, only assigning it when it is finished. Due to this, until the list is fully initialized, all threads have to enter the lock, then they will check that the list is now initialized and return.
This will result in some minor locking overhead, but it is not as strict as locking the collection for all reads.
Furthermore, since the collection is supposed to be read only as written here, I've made it into IReadOnlyList instead of the current IList.
Testing
I got a reproduction, although a bit clunky.
First commit checks should fail. Then I will push the fix which should succeed.