[release/11.0] Fix concurrent Unix named mutex creation - #134596
Merged
Merged
Conversation
## Why Concurrent shared compilations on Linux can intermittently fail when a newly created named mutex is initially owned. The creator can lose the mutex between publishing the shared state and recording ownership, causing a later `ReleaseMutex` to fail with "Cannot release a lock that is not owned by the current thread." ## What changed - Keep the creation/deletion process lock held through nonblocking initial mutex acquisition and ownership bookkeeping. - Preserve the existing behavior of releasing that lock before blocking waits. - Add a Unix regression test covering concurrent same-name constructors with initial ownership. ## Testing - `./build.sh clr+libs -rc checked` - `./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc checked` - `dotnet test src/libraries/System.Threading/tests/System.Threading.Tests.csproj --no-build` (714 passed) - Focused regression test passed. Resolves #134043 > [!NOTE] > This pull request description was generated with GitHub Copilot assistance. --------- Co-authored-by: Jeremy Koritzinsky <Jeremy.Koritzinsky@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
jkoritzinsky
approved these changes
Sep 24, 2026
This was referenced Sep 24, 2026
Member
|
/ba-g known issues. |
JulieLeeMSFT
approved these changes
Sep 25, 2026
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.
Backport of #134111 to release/11.0
/cc @jkoritzinsky
Customer Impact
Creating a new named mutex with the
initiallyOwnedparameter set totruefrom two threads in the same process could allow one of the threads to proceed without owning the mutex on Unix platforms.This was found by Roslyn in their move to use multithreaded MSBuild tasks.
Regression
#117635
Testing
Unit test added that forces this particular race many times in a loop until it occurs.
Risk
Low, only touches named mutex logic and the test validates the exact failure case reliably (always hits in the first 150 iterations on failure).