Repository navigation
Conversation
Open native client mutexes without initial ownership and acquire them through the existing timed synchronous wait. Preserve Mono and server-election behavior, track abandoned ownership for disposal, and retain thread diagnostics for release failures. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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. |
Rethrow captured test-thread exceptions through ExceptionDispatchInfo after the bounded join so failed ownership assertions retain their original type and stack. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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. |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The mutex ownership and cross-runtime concurrency changes require final human review.
Pull request overview
This PR avoids constructor-time ownership races for compiler client mutexes while preserving existing server/cache behavior.
Changes:
- Adds explicit client-mutex acquisition and abandonment tracking.
- Expands release diagnostics for runtime exception differences.
- Adds mutex lifecycle, timeout, and concurrency regression tests.
File summaries
| File | Summary |
|---|---|
src/Compilers/Shared/BuildServerConnection.cs |
Implements non-owning client mutex acquisition and ownership-safe disposal. |
src/Compilers/Server/VBCSCompilerTests/BuildServerConnectionTests.cs |
Adds mutex lifecycle and concurrent-request regression coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
3 of 4 tasks
jjonescz
approved these changes
Sep 17, 2026
Co-authored-by: Jan Jones <jan.jones.cz@gmail.com>
jjonescz
reviewed
Sep 18, 2026
AlekseyTs
approved these changes
Sep 18, 2026
4 of 14 tasks
karolz-ms
added a commit
to microsoft/aspire
that referenced
this pull request
Sep 24, 2026
## Description Project Resource V2 makes the dashboard available earlier, but coordinated project builds can delay full application readiness. .NET SDK 11 RC1 introduces the `-mt` MSBuild switch, which allows supported project builds to use multithreaded task execution. This change: - Detects the `dotnet` SDK selected for each build context, including `global.json` selection and prerelease versions. - Enables `-mt` for coordinated traversal builds and project rebuild commands when the selected SDK supports the target: - Project and generated traversal builds use `11.0.100-rc.1` or newer. - File-based `.cs` builds use `11.0.100-rtm.26473.104` or newer; stable `11.0.100` and later are included. - Uses the stricter file-based build floor because earlier .NET 11 prereleases lack both safe `-mt` argument forwarding and the compiler-client mutex mitigation. The required fixes landed in dotnet/sdk#56207, dotnet/roslyn#85675, and dotnet/dotnet#9565. - Caches version probes by SDK-selection context and refreshes the result when `global.json` changes. - Reuses the same provider for existing file-based app and .NET tool SDK validation. - Omits `-mt` when version detection fails, preserving the existing build behavior. Validation: - `.\restore.cmd` - `./restore.sh` - Affected `Aspire.Hosting` and `Aspire.Hosting.Dotnet` build completed with zero warnings and errors. - 47 focused provider, version-policy, coordinated-build, rebuild, file-app, and .NET-tool tests passed. - 15 focused `Aspire.Hosting.Tests` file-app SDK policy and environment-aware provider cases passed. - 6 focused `Aspire.Hosting.Dotnet.Tests` file-only build, rebuild, mixed-model coordination, and configured rebuild argument cases passed. - A repository-local .NET 11 RC1 `.csproj` build completed successfully with `-mt`. - A full `Aspire.Hosting.Tests` run encountered two unrelated `MSBuildTests` timeouts in `dotnet build --disable-build-servers`; both timeouts reproduced when retried in isolation. Fixes #19944 ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - If yes, did you have an API Review for it? - [ ] Yes - [ ] No - Did you add `<remarks />` and `<code />` elements on your triple slash comments? - [ ] Yes - [ ] No - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - If yes, have you done a threat model and had a security review? - [ ] Yes - [ ] No - [x] No --------- Co-authored-by: Copilot App <223556219+Copilot@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
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.
Summary
Related to dotnet/runtime#134043 (transferred from #85264). This is a compiler-client workaround, not a fix for the underlying runtime issue.
WaitOnereports abandonment, then rethrow for existing caller handling. Include bothApplicationExceptionandInvalidOperationExceptionin release diagnostics, preserving thread IDs and the original inner exception.ExceptionDispatchInfo, preserving the original assertion and stack.No global lock, await across mutex ownership, shared-compilation disablement, task isolation, or runtime changes.
Upstream validation
The initial upstream port passed 18/18 focused tests on each of
net10.0andnet472, zero skips, on Windows with repository SDK11.0.100-preview.6.26359.118andRunAnalyzersDuringBuild=true: allBuildServerConnectionTests, bothCompilerServerApiTest.Mutex*server-election tests, and the three existing cache-lock tests.Microsoft.Build.Tasks.CodeAnalysisbuilt fornet10.0/net472, andMicrosoft.Build.Tasks.CodeAnalysis.Sdkfornet472, with analyzers and zero warnings/errors.What the five tests prove
Three independent source-level mutants were compiled successfully and exercised against both the originally published tests and the final exception-preserving helper. Compilation failures were not counted as red results.
ClientMutexRequiresExplicitAcquisitionOpenOrCreateMutex, retaining the new API shape. This does not independently reproduce the runtime race.Assert.False(holdsMutex), expected false, actual true.AbandonedClientMutexIsReleasedIsLocked = truefrom the abandonment catch but retain the rethrow. An extra raw handle keeps the named object alive.TryLock(0)assertion expected true, actual false. The final helper reports this original assertion directly rather than wrapping it inAssert.Null.ClientMutexReleaseFailureIncludesThreadIdsApplicationException-only filter.11.0.0-rc.1.26453.118: exact exception assertion expectedSystem.Exception, actualSystem.InvalidOperationExceptionwith "Cannot release a lock that is not owned by the current thread." The same mutant passed on Windows, so Windows alone does not cover this regression.ClientMutexTimeoutDoesNotStartServerCannotConnectResponsewithout attempting server creation.UseExistingServerConcurrentlyAfter restoring the unchanged production DLL, all five final tests passed, zero skips, on Windows with the
net10.0payload running on .NET11.0.0-preview.6.26359.118, Windows with thenet472payload running on .NET Framework4.8.9345.0, and Ubuntu/WSL with the affected .NET11.0.0-rc.1.26453.118runtime. Linux usedDOTNET_ROLL_FORWARD=MajorandDOTNET_ROLL_FORWARD_TO_PRERELEASE=1for thenet10.0payload.The final test assemblies were recompiled into isolated output using the recorded analyzer-enabled compiler invocations. The original production source and all 2,033 original build-output files remained hash-identical. Changed-file formatting and diff checks passed; MSBuild invocations captured separate binary logs. The follow-up commit changes only the test helper/import, not production logic or the SDK-gated patch.
Matched SDK gate (before the upstream port)
Ubuntu 24.04 x64 under WSL; SDK
11.0.100-rc.1.26453.118, runtime11.0.0-rc.1.26453.118. Both runs used the same 32 project references plus app, harness, and flags:Stock failed on build 15: native initial acquisition returned
EBUSY, thenServerNamedMutex.Disposefailed on the same native thread. The patched SDK passed all 50 builds. Replay of all 50 binlogs using the matching SDK counted 1,650 Csc tasks and 1,650 compiler-server completions, with zero command-line fallbacks, external TaskHost routing messages, or errors. No initial-acquisitionEBUSYor ownership failure was recorded in the patched run.The task DLL was rebuilt from SDK-matching VMR sources at
3c8d132bfb012af4bbba80de22149a9f58e737f0, using stock SDK MSBuild assemblies and preserving the protocol commit hash. This was an unsigned development assessment overlay, not an officially source-built current-main SDK. Full SDK file hashes differ only for the task DLL and its added PDB; the compiler server, runtime, targets, and other files are unchanged. The production diff in this upstream port matches the gated patch exactly.Limits: Both SDK runs used the same observation-only native library and first-chance hook, which may affect timing. Finite stress results do not establish absence of all races or a customer failure rate. Mono/macOS execution and performance impact were not assessed.
Microsoft Reviewers: Open in CodeFlow