Repository navigation
Stop dotnet restore hanging when MSBuild worker nodes inherit its output - #1323
Merged
GrahamTheCoder merged 2 commits intoNov 18, 2026
Merged
GrahamTheCoder merged 2 commits into
GrahamTheCoder merged 2 commits into
Conversation
ProcessRunner waits for the child's redirected stdout/stderr to reach EOF. When MSBUILDENSURESTDOUTFORTASKPROCESSES=1 is inherited (dotnet test sets it), MSBuild launches worker nodes without redirecting their streams, so newly launched reusable nodes keep our pipes open after the build ends and the wait never completes. It hung MultiFileSolutionAndProjectTests intermittently, whenever restore had to launch new nodes. Disable node reuse for processes we run, so the nodes exit with the build. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8FVAmHV9bscZ82CChg
…ad of a restore A parallel build of two SDK-less projects is enough to make MSBuild launch a worker node, so the test no longer adds a second restore of the characterization solution to the run. It takes ~0.6s, needs no NuGet or SDK evaluation, and no longer needs the MSBuild collection since it uses its own temp directory. It still fails without MSBUILDDISABLENODEREUSE. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8FpweGikrBKYdcSCS1
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
MultiFileSolutionAndProjectTestssometimes stopped making progress, and after 5 minutes the blame hang timeout reported it as "Test host process crashed". The hang is indotnet restore, which runs before any conversion code, so the code under test isn't involved.Root cause
A hang dump showed no thread doing work: CPU use was 0%, no locks were held, and no thread was in CodeConverter code.
dumpasyncshowed the test stuck here:dotnet restoreprocess had already exited (ProcessWaitState._exited = 1).MSBUILDENSURESTDOUTFORTASKPROCESSES=1.dotnet testsets this for its children, and the testhost passes it on./nodeReuse:truenodes therefore inherit our pipes and keep running after the build, waiting to be reused.Repro
I ran
dotnet restoreon the characterization solution with piped output, the testhost's environment, and a randomMSBUILDNODEHANDSHAKESALT, which forces MSBuild to launch new nodes:MSBUILDENSURESTDOUTFORTASKPROCESSESremovedMSBUILDDISABLENODEREUSE=1-nodeReuse:false--disable-build-serversFix
ProcessRunnernow setsMSBUILDDISABLENODEREUSE=1for every process it starts. Worker nodes then exit when the build finishes, the pipes close and the wait completes. Setting it inProcessRunnercovers everyGetOutputAsynccaller: the restore,dotnet msbuild -getPropertyandgit diff. The XML doc comment records the reasoning.I left out a timeout on waiting for EOF after the process exits.
Process.WaitForExitAsyncalready waits for EOF internally, so a timeout would mean replacing it with our own handling of the exit event. It could also cut off output that a legitimately slow child is still writing. With the cause fixed, that complexity isn't worth it.Needs your confirmation
ProcessRunnerstarts, including the CLI's restore outside tests. The cost is starting new nodes on each run, about a second for a restore.Tests
ProcessRunnerTests.GetOutputAsyncReturnsWhenRestoreLeavesNewWorkerNodesRunningAsync. It restores the characterization solution throughGetOutputAsyncwithMSBUILDENSURESTDOUTFORTASKPROCESSES=1and a unique handshake salt, then waits at most 3 minutes for the output to end.--blame-hang --blame-hang-timeout 5m. Every run gave 1426 passed, 5 skipped and 0 failed. That matches the baseline of 1425/5/0 plus the new test.Generated by Claude Code