Skip to content

[release/11.0] Fix concurrent Unix named mutex creation - #134596

Merged
JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-134111-to-release/11.0
Sep 25, 2026
Merged

JulieLeeMSFT merged 1 commit into
release/11.0from
backport/pr-134111-to-release/11.0

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #134111 to release/11.0

/cc @jkoritzinsky

Customer Impact

  • 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

  • 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).

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

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @VSadov
See info in area-owners.md if you want to be subscribed.

@JulieLeeMSFT

Copy link
Copy Markdown
Member

/ba-g known issues.

@JulieLeeMSFT
JulieLeeMSFT merged commit 4c29572 into release/11.0 Sep 25, 2026
139 of 144 checks passed
@JulieLeeMSFT
JulieLeeMSFT deleted the backport/pr-134111-to-release/11.0 branch September 25, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Threading Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants