Fix dotnet test hang when the test app process exits but a child process of it remains alive#52558
Merged
Evangelink merged 12 commits intomainfrom Feb 11, 2026
Merged
Fix dotnet test hang when the test app process exits but a child process of it remains alive#52558Evangelink merged 12 commits intomainfrom
Evangelink merged 12 commits intomainfrom
Conversation
d85c966 to
5a6a120
Compare
This was referenced Jan 20, 2026
9b86fd8 to
8a0ae25
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a test case and implementation changes to prevent dotnet test from hanging when a test application exits but leaves a child process alive that has inherited stdout/stderr handles. The fix modifies the Microsoft Testing Platform (MTP) test runner to wait for process exit independently of consuming stdout/stderr, with a 5-second timeout for output consumption after the process has exited.
Changes:
- Modified TestApplication.RunAsync to wait for process exit before reading stdout/stderr, with a 5-second timeout to handle orphaned child processes
- Added WaitForExitWithoutOutputAsync helper method that waits for process exit without blocking on output streams
- Added MTPChildProcessHangTest test project that simulates a test app spawning a hanging child process
- Added a skipped test case to verify the fix (skipped because test infrastructure itself has the same issue)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs | Changed stdout/stderr reading to use line-based reading with StringBuilder, implemented WaitForExitWithoutOutputAsync, and added 5-second timeout after process exit |
| test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs | Added skipped test case for MTP child process hang scenario |
| test/TestAssets/TestProjects/MTPChildProcessHangTest/MTPChildProcessHangTest.csproj | Test project configuration for hanging child process scenario |
| test/TestAssets/TestProjects/MTPChildProcessHangTest/global.json | Configures test to use Microsoft.Testing.Platform runner |
| test/TestAssets/TestProjects/MTPChildProcessHangTest/Program.cs | Test implementation that spawns a hanging child process during test execution |
Evangelink
approved these changes
Feb 10, 2026
Evangelink
reviewed
Feb 11, 2026
Closed
Member
Author
|
/backport to release/10.0.3xx |
Contributor
|
Started backporting to |
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.
Fixes #51507