Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fixing the contention condition caused by RegisterResolversManifests - #11079

#11079
Merged
SimaTian merged 13 commits into
maindotnet/msbuild:mainfrom
SdkResolverService_race_fixdotnet/msbuild:SdkResolverService_race_fixCopy head branch name to clipboard
Dec 16, 2024
Merged

Fixing the contention condition caused by RegisterResolversManifests#11079
SimaTian merged 13 commits into
maindotnet/msbuild:mainfrom
SdkResolverService_race_fixdotnet/msbuild:SdkResolverService_race_fixCopy head branch name to clipboard

Conversation

@SimaTian

@SimaTian SimaTian commented Dec 4, 2024

Copy link
Copy Markdown
Contributor

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.

@SimaTian
SimaTian force-pushed the SdkResolverService_race_fix branch 2 times, most recently from 532900a to 2cdfbf7 Compare December 6, 2024 09:59
@SimaTian SimaTian changed the title Fixing the race condition caused by RegisterResolversManifests Fixing the contention condition caused by RegisterResolversManifests Dec 6, 2024
@SimaTian
SimaTian force-pushed the SdkResolverService_race_fix branch from 2cdfbf7 to d7826cd Compare December 6, 2024 10:18

@donJoseLuis donJoseLuis left a comment

Copy link
Copy Markdown

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

Comment thread src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs Outdated
Comment thread src/Build.UnitTests/BackEnd/SdkResolverService_Tests.cs Outdated

@JanKrivanek JanKrivanek left a comment

Copy link
Copy Markdown
Member

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

Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated

@JanKrivanek JanKrivanek left a comment

Copy link
Copy Markdown
Member

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!!

Comment thread src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Outdated
@SimaTian
SimaTian merged commit 3a63bca into main Dec 16, 2024
@SimaTian
SimaTian deleted the SdkResolverService_race_fix branch December 16, 2024 10:25
@KalleOlaviNiemitalo

Copy link
Copy Markdown

@baronfel

Copy link
Copy Markdown
Member

/backport to vs17.12

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to vs17.12: https://github.com/dotnet/msbuild/actions/runs/13973433101

This was referenced Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collection was modified in SdkResolverService.ResolveSdkUsingResolversWithPatternsFirst

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.