Skip to content

Scope compiler server mutexes per-user - #86056

Merged
jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:local-mutex
Oct 22, 2026
Merged

jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:local-mutex

Conversation

@jjonescz

@jjonescz jjonescz commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

The corresponding named pipes are already per-user. On non-Windows, per-user is now the default anyway, so this PR unifies the Windows behavior.

cc @jaredpar @agocke

Microsoft Reviewers: Open in CodeFlow

@jjonescz
jjonescz requested review from agocke and jaredpar and a balanced review from Copilot October 14, 2026 13:43
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🔵 Needs a closer look

Mutex ACL behavior is security-sensitive across Windows, .NET Framework, and Unix, and CI remains in progress.

0 open findings

What changed in this PR

Scopes compiler-server mutexes per user while preserving cross-user cache coordination.

Changes:

  • Adds modern .NET and .NET Framework user isolation.
  • Adds platform-specific mutex tests.
  • Documents cache mutex scope.

Holistic assessment: No concrete defects found, but the security-sensitive, cross-framework behavior warrants human validation.

File Description
BuildServerConnection.cs Implements per-user mutex creation and validation.
ServerNamedMutexTests.cs Tests user and legacy mutex scopes.
CompilationCacheTests.cs Preserves cross-user cache test locking.
BuildServerConnectionTests.cs Updates tests to use scoped mutexes.
CompilationCache.cs Keeps cache-entry mutexes cross-user.
compiler-output-cache-experiment.md Documents cache path and mutex scope.

🧠 Review effort: Balanced

@jjonescz
jjonescz marked this pull request as ready for review October 15, 2026 12:14
@jjonescz
jjonescz requested a review from a team as a code owner October 15, 2026 12:14
Copilot AI balanced review requested due to automatic review settings October 15, 2026 12:14

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.

🔵 Needs a closer look

Security-sensitive Windows access checks and cross-runtime interoperability need platform-specific validation that was unavailable during review.

0 open findings

🧠 Review effort: Balanced


Per-entry synchronization is used so that multiple writers racing on the same key do not all try to publish the same result concurrently. If another process is already populating an entry, the current request simply continues with normal compilation behavior.

Cache-entry mutexes use cross-session, cross-user scope so processes sharing a cache directory use the same locks, subject to operating-system access controls. This differs from compiler-server startup and lifetime mutexes, which are restricted to the current user. Mutex scope does not replace access controls on the cache directory.

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.

Consider moving this comment to the TryAcquireEntryMutex code in CompilationCache. Otherwise, the currentUserOnly: false stands out a bit.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 10:06

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.

🔵 Needs a closer look

Security-sensitive Windows access checks and cross-runtime mutex interoperability warrant human review with platform-specific validation.

No open issues 🎉

Review effort: Balanced


```text
<temp>/roslyn-cache
<LocalApplicationData>/roslyn-cache

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.

Should we use well-known user cache dirs instead?

@jjonescz jjonescz Oct 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I can look into that, thanks. That seems orthogonal to this PR though.

@jjonescz
jjonescz requested a review from 333fred October 20, 2026 12:32
@jjonescz

Copy link
Copy Markdown
Member Author

@333fred for another look, thanks

@jjonescz
jjonescz merged commit 5ef5dd9 into dotnet:main Oct 22, 2026
22 checks passed
@jjonescz
jjonescz deleted the local-mutex branch October 22, 2026 08:11
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Oct 22, 2026
var mutexName = GetCacheEntryMutexName(dllName, hashKey);
if (!createIfMissing && !ServerNamedMutex.WasOpen(mutexName))
if (!createIfMissing && !ServerNamedMutex.WasOpen(mutexName, currentUserOnly: false))

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.

Can you actually fulfill the requirements here? Docs say that all users on the machine must be trusted to use global mutexes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants