-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix TimeoutException when DOTNET_CLI_USE_MSBUILD_SERVER=true on .NET 10.0.300 #13716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rainersigwald
merged 13 commits into
main
from
copilot/fix-timeout-exception-during-build
May 14, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34cc9d2
Initial plan
Copilot 2b21ff0
Pass DOTNET_ROOT env overrides when launching MSBuild server node
Copilot 9e1ddf4
Improve server-launch diagnostics; fall back to in-proc on connect fa…
Copilot c84ecd1
Address review comments: drop placeholder issue link, enable nullable…
Copilot 794f83f
Address review: localize fallback messages, surface "server crashed" …
Copilot b9eb4ac
Merge branch 'main' into copilot/fix-timeout-exception-during-build
JanProvaznik 98f009d
Address review feedback: tighten test, neutralize fallback wording, c…
JanProvaznik ef83ce7
Merge branch 'main' into copilot/fix-timeout-exception-during-build
JanProvaznik 2514bf2
Merge remote-tracking branch 'origin/main' into copilot/fix-timeout-e…
rainersigwald 3df368f
Condense DOTNET_ROOT comment in MSBuildClient.TryLaunchServer
rainersigwald 6c378ce
Potential fix for pull request finding
rainersigwald e38dea6
Remove MSBUILDDEBUGCOMM mention and apply suggested wording in fallba…
Copilot c5a09b3
Potential fix for pull request finding
rainersigwald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using System.Threading; | ||
| using Microsoft.Build.Experimental; | ||
| using Microsoft.Build.UnitTests; | ||
| using Shouldly; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Build.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// Tests for the <see cref="MSBuildClient"/> fallback behaviour. | ||
| /// </summary> | ||
| public class MSBuildClient_Tests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public MSBuildClient_Tests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// When the configured msbuild executable does not exist, launching the server fails. | ||
| /// <see cref="MSBuildClient.Execute"/> must return a recoverable exit type rather than | ||
| /// letting an exception escape — it is the host's contract that any failure inside | ||
| /// Execute routes through <see cref="MSBuildClientExitResult"/> so callers (e.g. | ||
| /// <c>MSBuildClientApp</c>) can fall back to in-process execution. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Regression coverage for the .NET 10.0.300 / Aspire timeout: when | ||
| /// <c>DOTNET_CLI_USE_MSBUILD_SERVER=true</c> is honoured but the server child cannot | ||
| /// start (e.g. the apphost can't find the .NET runtime), <see cref="MSBuildClient.Execute"/> | ||
| /// must not propagate a <see cref="System.TimeoutException"/> or any other exception. | ||
| /// Pre-fix, an uncaught <c>TimeoutException</c> from <c>NamedPipeClientStream.Connect</c> | ||
| /// escaped past <c>MSBuildClientApp</c> and crashed the CLI; this test locks in the | ||
| /// no-exception-escape contract by simply calling <c>Execute</c> outside any try/catch | ||
| /// and asserting on the structured result. | ||
| /// </remarks> | ||
| [Fact] | ||
| public void Execute_WithUnreachableServer_DoesNotPropagateException() | ||
| { | ||
| // Isolate from any real MSBuild server / DOTNET_CLI_USE_MSBUILD_SERVER state on | ||
| // the dev or CI machine. Without this the named-mutex check in MSBuildClient can | ||
| // observe a warm server from another test/run, which makes the assertions below | ||
| // non-deterministic. | ||
| using TestEnvironment env = TestEnvironment.Create(_output); | ||
| env.SetEnvironmentVariable("DOTNET_CLI_USE_MSBUILD_SERVER", null); | ||
| env.SetEnvironmentVariable("MSBUILDUSESERVER", null); | ||
|
|
||
| string[] commandLine = ["dummy.proj"]; | ||
| string nonexistentMsBuild = Path.Combine( | ||
| Path.GetTempPath(), | ||
| "msbuildclient-tests-" + Guid.NewGuid().ToString("N"), | ||
| "MSBuild.dll"); | ||
|
|
||
| MSBuildClient client = new MSBuildClient(commandLine, nonexistentMsBuild); | ||
|
|
||
| // The whole point of the regression fix: this must NOT throw. xUnit fails the | ||
| // test with the offending stack if any exception escapes, which is the | ||
| // primary regression contract being verified. | ||
| MSBuildClientExitResult result = client.Execute(CancellationToken.None); | ||
|
|
||
| result.ShouldNotBeNull(); | ||
|
|
||
| // The unreachable-server path must produce one of the recoverable failure types | ||
| // so that MSBuildClientApp can fall back to in-process execution. Crucially, | ||
| // ServerBusy is excluded here: ServerBusy is the "another client is racing for | ||
| // the launch mutex" path and is not what an unreachable server should produce — | ||
| // accepting it would mask a real regression where the failure was misclassified. | ||
| result.MSBuildClientExitType.ShouldBeOneOf( | ||
| MSBuildClientExitType.LaunchError, | ||
| MSBuildClientExitType.UnableToConnect, | ||
| MSBuildClientExitType.UnknownServerState); | ||
|
|
||
| // No server child was successfully launched, so the diagnostic helper should not | ||
| // have observed an exit code. (Once issue #13718 lands and the diagnostic helper | ||
| // is plumbed through every connect failure, this gives MSBuildClientApp the right | ||
| // signal to pick the generic "server unavailable" message rather than the more | ||
| // specific "crashed with exit code N" one.) | ||
| result.ServerProcessExitCode.ShouldBeNull(); | ||
| } | ||
| } | ||
| } |
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
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
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
|
rainersigwald marked this conversation as resolved.
|
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.