Skip to content

Fix product process-output hang and process-wrapper leaks - #70076

Merged
adamsitnik merged 5 commits into
dotnet:mainfrom
adamsitnik:modernize-process-apis
Nov 17, 2026
Merged

adamsitnik merged 5 commits into
dotnet:mainfrom
adamsitnik:modernize-process-apis

Conversation

@adamsitnik

@adamsitnik adamsitnik commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fix product process-output hang and process-wrapper leaks

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Fix an output-pipe hang in dotnet-openapi and release leaked Process wrappers.

Description

Following review feedback, this PR now contains only product bug fixes, so they can be considered for backporting. The rest of the original changes moved to separate PRs:

The original commits are kept in the history; the last commit reverts everything except the fixes below.

Bug fixes

  • dotnet-openapi package installation: the tool waited for dotnet add package to exit before reading its redirected stdout/stderr. When the command produced enough output to fill a pipe, the child blocked and the tool reported a false 20-second timeout instead of the actual failure. The output is now drained while the command runs; the existing timeout message and package-reference fallback are preserved, and a timed-out command is cleaned up.
  • Components.Testing ParentProcessWatcher: dispose the monitored parent Process wrapper. Polling and shutdown behavior are unchanged.
  • SpaProxy shutdown scripts: dispose the two launched Process wrappers. This releases wrapper resources only; it does not stop the shutdown scripts and does not fix the existing check-after-start timing race.

No public API changes. The OpenAPI fix uses the .NET 11 Process.RunAndCaptureTextAsync API, so a backport to older releases would need a different implementation.

This work started as a real-world test of the process-api-net11 skill in dotnet/skills#1322.

Validation

On Windows, with the same file content on a branch based on main:

  • dotnet test src\Tools\Microsoft.dotnet-openapi\test\dotnet-microsoft.openapi.Tests.csproj --filter 'FullyQualifiedName~OpenApiAddFileTests' — passed.
  • Microsoft.AspNetCore.Components.Testing and Microsoft.AspNetCore.SpaProxy — built successfully.

The two disposal fixes have no dedicated tests. macOS/Linux SPA shutdown-script behavior was not runtime-tested.

Related issue: none linked.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 13:02
@github-actions github-actions Bot added area-blazor Includes: Blazor, Razor Components area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI area-grpc Includes: GRPC wire-up, templates area-hosting Includes Hosting labels Oct 28, 2026
@adamsitnik
adamsitnik requested a review from wtgodbe as a code owner October 28, 2026 13:02
@github-actions github-actions Bot added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions area-signalr Includes: SignalR clients and servers labels Oct 28, 2026
@adamsitnik
adamsitnik requested a review from a team as a code owner October 28, 2026 13:02

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

Cross-platform process-lifetime changes, especially IIS Express parent-exit cleanup and Unix monitoring, lack final-revision runtime validation and require human verification on supported operating systems.

No open issues 🎉

What changed in this PR

Modernizes process management across ASP.NET Core tooling, shared infrastructure, and tests using .NET 11 APIs. It also provides practical feedback for the process-api-net11 skill without changing shipping public APIs.

Changes:

  • Replaces eligible output-capture and exit-waiting code with built-in process APIs while retaining live logging and readiness handling.
  • Updates timeout, cancellation, process cleanup, signaling, and inherited-handle configuration.
  • Removes an unused OpenAPI test helper and preserves an older-framework compatibility path.

Validation of the final revision remains limited; full cross-platform and browser E2E validation has not been completed.

File Description
src/​Tools/​Shared/​TestHelpers/​NativeAotToolRunner.cs Uses combined output capture and exit-status waits.
src/​Tools/​Shared/​SecretsHelpers/​ProjectIdResolver.cs Replaces event-based capture with RunAndCaptureText.
src/​Tools/​Microsoft.dotnet-openapi/​test/​ProcessEx.cs Removes the unused process wrapper.
src/​Tools/​Microsoft.dotnet-openapi/​src/​Commands/​BaseCommand.cs Captures package-install output asynchronously with a timeout.
src/​Tools/​dotnet-getdocument/​src/​Exe.cs Uses a kill-on-timeout wait and returned exit status.
src/​SignalR/​server/​StackExchangeRedis/​test/​Docker.cs Kills timed-out commands and uses exit-status results.
src/​SignalR/​perf/​benchmarkapps/​Crankier/​Agent.cs Sends unread worker stderr to a null handle.
src/​Shared/​Process/​ProcessExtensions.cs Uses built-in output capture with a timeout.
src/​Shared/​Process/​ProcessEx.cs Sets an explicit inherited-handle list.
src/​Shared/​E2ETesting/​SauceConnectServer.cs Configures handle inheritance for tunnel and sentinel launches.
src/​Shared/​CertificateGeneration/​UnixCertificateManager.cs Sets inherited-handle lists for certificate commands.
src/​Shared/​CertificateGeneration/​MacOSCertificateManager.cs Updates handle inheritance and certificate-command exit waiting.
src/​Servers/​Kestrel/​test/​Interop.FunctionalTests/​H2SpecCommands.cs Replaces manual exit tracking with a cancellation-aware wait.
src/​Servers/​IIS/​IntegrationTesting.IIS/​src/​IISExpressDeployer.cs Uses parent-exit cleanup and exit-status waits.
src/​Servers/​IIS/​IIS/​test/​Common.FunctionalTests/​Infrastructure/​Helpers.cs Uses a timed exit-status assertion.
src/​Servers/​IIS/​IIS/​test/​Common.FunctionalTests/​Infrastructure/​AppVerifier.cs Captures command output through the built-in runner.
src/​Servers/​HttpSys/​test/​FunctionalTests/​ServerTests.cs Removes duplicate process starts and awaits command exit.
src/​OpenApi/​test/​Microsoft.AspNetCore.OpenApi.Build.Tests/​GenerateAdditionalXmlFilesForOpenApiTests.cs Combines output capture while retaining explicit tree cleanup.
src/​Middleware/​WebSockets/​test/​ConformanceTests/​Autobahn/​Executable.cs Streams output lines and updates cancellation cleanup.
src/​Middleware/​StaticFiles/​test/​UnitTests/​StaticFileMiddlewareTests.cs Uses Process.Run with structured symlink arguments.
src/​Middleware/​Spa/​SpaServices.Extensions/​src/​Npm/​NodeScriptRunner.cs Sets an explicit inherited-handle list.
src/​Middleware/​Spa/​SpaProxy/​src/​SpaProxyLaunchManager.cs Disposes shutdown-script wrappers and checks exit status.
src/​Hosting/​test/​FunctionalTests/​ShutdownTests.cs Sends SIGTERM directly and uses a kill-on-timeout wait.
src/​Hosting/​Server.IntegrationTesting/​src/​Deployers/​SelfHostDeployer.cs Configures handle inheritance for hosted applications.
src/​Hosting/​Server.IntegrationTesting/​src/​Deployers/​RemoteWindowsDeployer/​RemoteWindowsDeployer.cs Configures handle inheritance for PowerShell launches.
src/​Hosting/​Server.IntegrationTesting/​src/​Deployers/​NginxDeployer.cs Uses Environment.UserName and explicit timed exit checks.
src/​Hosting/​Server.IntegrationTesting/​src/​ApplicationPublisher.cs Disposes the process wrapper and uses parent-only exit-status waits.
src/​Grpc/​Interop/​test/​InteropTests/​Helpers/​WebsiteProcess.cs Configures handle inheritance for test servers.
src/​Grpc/​Interop/​test/​InteropTests/​Helpers/​ClientProcess.cs Configures handle inheritance for test clients.
src/​Fuzzing/​AspNetCoreFuzzing/​Program.cs Configures handle inheritance for instrumentation commands.
src/​Components/​WebView/​test/​StaticWebAssets/​ConsumerBuild.cs Reads combined output lines within a shared timeout budget.
src/​Components/​WebView/​test/​E2ETest/​WebViewManagerE2ETests.cs Reads output asynchronously and disposes the process wrapper.
src/​Components/​WebAssembly/​Server/​src/​DebugProxyLauncher.cs Simplifies startup and timeout-registration disposal.
src/​Components/​Testing/​test/​PackageIntegrationTests.cs Drains output concurrently and kills the app on readiness failure.
src/​Components/​Testing/​src/​Infrastructure/​ServerInstance.cs Uses exit-status waits for readiness monitoring and disposal.
src/​Components/​Testing/​src/​Infrastructure/​ParentProcessWatcher.cs Uses process lookup and an asynchronous wait instead of polling.
src/​Components/​Gateway/​test/​GatewayToolInstallation.cs Uses timed output enumeration and exit-status waits.
src/​Caching/​StackExchangeRedis/​test/​Infrastructure/​RedisTestConfig.cs Adds .NET 11 handle configuration behind a framework guard.
.github/​skills/​review-pull-request/​tests/​PrepareReviewTests.cs Captures Git stdout and stderr together as bytes.
.github/​skills/​review-pull-request/​scripts/​prepare-review.cs Updates handle inheritance and process-start handling.

Review effort: Balanced

@adamsitnik adamsitnik left a comment

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.

I've left comments, so other reviewers can understand the reasoning behind the changes and avoid similar issues in the future.

Comment thread src/Shared/Process/ProcessExtensions.cs Resolved
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@adamsitnik
adamsitnik force-pushed the modernize-process-apis branch from 373b346 to 9521117 Compare November 17, 2026 14:24
@adamsitnik adamsitnik changed the title Modernize process management with .NET 11 APIs Fix product process-output hangs and process-wrapper leaks Nov 17, 2026
@adamsitnik adamsitnik changed the title Fix product process-output hangs and process-wrapper leaks Modernize process management with .NET 11 APIs Nov 17, 2026
@adamsitnik
adamsitnik force-pushed the modernize-process-apis branch from 741e3a0 to 373b346 Compare November 17, 2026 15:11
Revert product improvements and test/infrastructure changes, which moved to separate PRs. Keep only the three product bug fixes:

- dotnet-openapi: drain redirected output while adding a package, so a full pipe no longer blocks the child and surfaces as a false timeout.
- Components.Testing ParentProcessWatcher: dispose the parent Process wrapper.
- SpaProxy: dispose the shutdown-script Process wrappers.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 151a6a4b-fb9b-4efa-bb7c-383fe6bc3a4c
@adamsitnik adamsitnik changed the title Modernize process management with .NET 11 APIs Fix product process-output hang and process-wrapper leaks Nov 17, 2026
adamsitnik added a commit to adamsitnik/aspnetcore that referenced this pull request Nov 17, 2026
…ation

The output-draining fix belongs to dotnet#70076.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 151a6a4b-fb9b-4efa-bb7c-383fe6bc3a4c
var timeout = 20;
if (!process.WaitForExit(timeout * 1000))

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.

to other code reviewers: this was a bug: waiting for exit and then reading std out and then reading std err.

We must read both std out and err at the same time and then wait for exit. Which is what Process.RunAndCaptureTextAsync does

@adamsitnik

Copy link
Copy Markdown
Member Author

@adamsitnik I think most of this looks good but I think it'd help reviewing if you could split test/product code changes and also bug fixes (since we might want to backport those) out of this PR

@akoeplinger done! This PR is now just product bug fixes, and #70669 and contain #70668 other changes.

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.

🟡 Changes recommended

The missing large-output regression test leaves the real dotnet add package path without coverage to detect the original pipe-buffer hang and confirm failure diagnostics are returned instead of a timeout.

1 open issue

Review effort: Balanced

@DeagleGross DeagleGross left a comment

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.

LGTM, lets add a test to lockdown the behavior

@adamsitnik
adamsitnik merged commit b113073 into dotnet:main Nov 17, 2026
31 checks passed
@adamsitnik
adamsitnik deleted the modernize-process-apis branch November 17, 2026 16:52
@github-actions

Copy link
Copy Markdown
Contributor

✅ No documentation PR was created.

Confidence that documentation is needed: 5%

No docs needed: internal bug fixes (dotnet-openapi output draining, Process wrapper disposal); no public API changes.

Documentation surfaces considered

  • Conceptual article: Not required — Bug fixes restoring expected behavior; no public API or documented behavior change.
  • Migration guidance: Not required — No user action needed on upgrade.
  • Breaking change: Not required — No compatibility impact.

adamsitnik added a commit to adamsitnik/aspnetcore that referenced this pull request Nov 17, 2026
Resolve conflicts with dotnet#70076 in ParentProcessWatcher and SpaProxyLaunchManager by keeping this branch's versions, which already include its process wrapper disposal.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 151a6a4b-fb9b-4efa-bb7c-383fe6bc3a4c
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 18, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 0d10563a Deployed Nov 17, 2026 by adamsitnik via conclusion #365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI area-grpc Includes: GRPC wire-up, templates area-hosting Includes Hosting area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions area-signalr Includes: SignalR clients and servers pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants