Skip to content

Fix concurrent Unix named mutex creation - #134111

Open
jkoritzinsky wants to merge 1 commit into
mainfrom
dev/jkoritzinsky/shiny-adventure
Open

jkoritzinsky wants to merge 1 commit into
mainfrom
dev/jkoritzinsky/shiny-adventure

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

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: Copilot <223556219+Copilot@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Add platform capability guards to prevent unsupported targets from failing or hanging.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

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.
File Description
src/​libraries/​System.Threading/​tests/​MutexTests.cs Adds concurrent named-mutex constructor coverage; requires guards for mobile, Browser, and Wasi.
src/​libraries/​System.Private.CoreLib/​src/​System/​Threading/​NamedMutex.Unix.cs Preserves locking during nonblocking ownership setup.

Comment on lines +915 to +916
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Concurrent shared compilations can fail releasing the client mutex on Linux

2 participants