You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Fixes a Unix named-mutex creation race by preserving the process lock through initial acquisition and ownership bookkeeping, with a concurrent regression test.
Changes:
Updates Unix mutex acquisition locking.
Adds concurrent initial-ownership coverage.
Test requires platform capability guards for unsupported targets.
This acquires the global creation/deletion process lock for every result, even though RecordMutexAcquisition immediately returns for TimedOut and AcquiredLockRecursively. A timed-out or recursive wait can therefore block behind unrelated named-mutex creation/deletion work despite doing no bookkeeping; only acquire the process lock when the raw result needs ownership recording.
Backport of #134111 to release/11.0
/cc @jkoritzinsky
## Customer Impact
- [x] Customer reported
- [ ] Found internally
Creating a new named mutex with the `initiallyOwned` parameter set to
`true` from 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
- [X] Yes
- [ ] No
#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).
Co-authored-by: Jeremy Koritzinsky <jekoritz@microsoft.com>
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>
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
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.
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
ReleaseMutexto fail with "Cannot release a lock that is not owned by the current thread."What changed
Testing
./build.sh clr+libs -rc checked./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc checkeddotnet test src/libraries/System.Threading/tests/System.Threading.Tests.csproj --no-build(714 passed)Resolves #134043
Note
This pull request description was generated with GitHub Copilot assistance.