Repository navigation
Modernize product process management APIs - #70669
adamsitnik merged 3 commits into
Conversation
Co-authored-by: Copilot <[email protected]> Copilot-Session: 151a6a4b-fb9b-4efa-bb7c-383fe6bc3a4c
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the process-management modernization changes.
No open issues 🎉
What changed in this PR
Modernizes process management in shipping ASP.NET Core tools and packages using newer .NET APIs. This is the product-modernization split; bug fixes and non-shipping infrastructure changes remain in separate PRs, with no public API changes introduced here.
Changes:
- Replace custom output capture and selected process waits with built-in APIs.
- Add explicit handle-inheritance lists at process launch sites.
- Simplify parent monitoring and debug-proxy cancellation handling, and improve SPA shutdown-script diagnostics.
| File | Description |
|---|---|
src/Tools/Shared/SecretsHelpers/ProjectIdResolver.cs |
Use built-in output capture for project-ID resolution. |
src/Tools/Microsoft.dotnet-openapi/src/Commands/BaseCommand.cs |
Set explicit handle inheritance for package commands. |
src/Tools/dotnet-getdocument/src/Exe.cs |
Use timeout-aware exit-status waiting. |
src/Shared/CertificateGeneration/UnixCertificateManager.cs |
Set explicit handle inheritance for certificate commands. |
src/Shared/CertificateGeneration/MacOSCertificateManager.cs |
Modernize certificate-command waiting and handle inheritance. |
src/Middleware/Spa/SpaServices.Extensions/src/Npm/NodeScriptRunner.cs |
Set explicit handle inheritance for Node script launches. |
src/Middleware/Spa/SpaProxy/src/SpaProxyLaunchManager.cs |
Update shutdown-script status checks and exit diagnostics. |
src/Components/WebAssembly/Server/src/DebugProxyLauncher.cs |
Simplify startup and cancellation-registration lifetime. |
src/Components/Testing/src/Infrastructure/ServerInstance.cs |
Modernize process launch and exit waits. |
src/Components/Testing/src/Infrastructure/ParentProcessWatcher.cs |
Replace polling with asynchronous parent-exit monitoring. |
Review effort: Balanced
|
/review |
adamsitnik
left a comment
There was a problem hiding this comment.
I've left comments, so other reviewers can understand the reasoning behind the changes and avoid similar issues in the future.
| var parent = Process.GetProcessById(_parentPid); | ||
|
|
||
| while (!stoppingToken.IsCancellationRequested) | ||
| if (Process.TryGetProcessById(_parentPid, out var parent)) |
There was a problem hiding this comment.
to other code reviewers: We don't get exception of parent has already exited
| // Also monitor for early process exit to fail fast with diagnostics. | ||
| var timeoutTask = Task.Delay(options.ReadinessTimeoutMs); | ||
| var processExitTask = _process.WaitForExitAsync(); | ||
| var processExitTask = _process.WaitForExitStatusAsync(); |
There was a problem hiding this comment.
to other code reviewers: WaitForExitStatusAsync does not wait for the process to report EOF when std out/err are redirected (this is what WaitForExitAsync and friend do), which can avoid hangs when child process spawned other processes that keep the pipe opened
| var stopProcess = Process.Start(stopScriptInfo); | ||
| if (stopProcess == null || stopProcess.HasExited) | ||
| var stopProcess = Process.Start(stopScriptInfo)!; | ||
| if (stopProcess.TryWaitForExitStatus(TimeSpan.Zero, out ProcessExitStatus? status)) |
There was a problem hiding this comment.
to other code reviewers: this check was and is still flaky (the process can fail a moment after the check). Copilot has just ported the code to the new API.
| process.BeginOutputReadLine(); | ||
| process.BeginErrorReadLine(); | ||
| process.WaitForExit(); | ||
| ProcessTextOutput processOutput = Process.RunAndCaptureText(psi); |
There was a problem hiding this comment.
to other code reviewers: this is not only simpler but also WAY faster
| environment, | ||
| appEntry.HarnessMode == E2EAppEntry.CompiledHarnessMode); | ||
|
|
||
| _process = Process.Start(startInfo) |
There was a problem hiding this comment.
to other code reviewers: Process.Start can return null only when UseShellExecute is set to true, here it's not.
| var startInfo = new ProcessStartInfo(executable, args) | ||
| { | ||
| UseShellExecute = false, | ||
| InheritedHandles = [], |
There was a problem hiding this comment.
to other code reviewers: this is what we recommend to always set. It makes the process inherit only std handles, without any other inheritable handles that are alive in the parent process. It also allows to spawn processes in parallel on Windows.
|
|
||
| var startInfo = new ProcessStartInfo(executable, args) | ||
| { | ||
| UseShellExecute = false, |
There was a problem hiding this comment.
to other code reviewers: UseShellExecute is set to false by default in modern .NET. When we don't set it at all, all the code related to it can be eliminated by the AOT compiler
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
7033a73 to
a6a076a
Compare
|
/review |
|
Copilot's local review panel found no issues to raise at this commit. All three independent arms (G/S/O) completed source review at Informational discarded checks (non-blocking) No candidate verifier was invoked: these were routine negative checks or worker questions settled by source inspection before verification. Existing explanatory author comments were deduplicated.
Posted for informational purposes so the author can confirm the verifier didn't discard or leave unresolved a real finding; this item does not block Untested coverage gaps and scope limits
Validation boundary: all arms were source-only; O additionally inspected runtime primary source and the pinned reference pack, not the exact runtime build's implementation. No target code, tests, builds, or browser workflows were executed by the panel. Human-directed and GitHub Copilot-generated. |
|
✅ No documentation PR was created. Confidence that documentation is needed: 8% No docs needed: the change is internal refactoring of process management with no public API or documented behavior change. Documentation surfaces considered
|
Modernize product process management APIs
Simplify product process management using modern .NET APIs.
Description
Product improvements split from dotnet/aspnetcore#70076, following review feedback. This branch starts directly from main, not from the product-fixes branch, and contains no non-shipping test/infrastructure changes. The test/infrastructure split is dotnet/aspnetcore#70668.
No measured throughput or binary-size improvement is claimed, and no shipping public API changes are introduced. Exit-status API substitutions are not presented as independently reproduced bug fixes. The SPA startup-status check retains its existing timing race.
Relationship to #70076: that PR (product bug fixes) has been merged, and this branch is merged with current main. The
ParentProcessWatcherandSpaProxyLaunchManagerchanges here build on itsProcesswrapper disposal; forBaseCommand.cs(dotnet-openapi) this PR only adds the explicit handle-inheritance list.This remains a real-world test of the
process-api-net11skill in dotnet/skills#1322.Validation
Commands ran on Windows after
. .\activate.ps1:dotnet test src\Tools\dotnet-user-secrets\test\dotnet-user-secrets.Tests.csproj --no-restore -v:q -p:UseIisNativeAssets=false— 51 passed, 1 skipped.dotnet test src\Tools\dotnet-user-jwts\test\dotnet-user-jwts.Tests.csproj -v:q -p:UseIisNativeAssets=false— 60 passed, 1 skipped.dotnet test src\Middleware\Spa\SpaServices.Extensions\test\Microsoft.AspNetCore.SpaServices.Extensions.Tests.csproj -v:q -p:UseIisNativeAssets=false— 14 passed.dotnet test src\Components\WebAssembly\Server\test\Microsoft.AspNetCore.Components.WebAssembly.Server.Tests.csproj -v:q -p:UseIisNativeAssets=false— 11 passed.dotnet test src\Shared\test\Shared.Tests\Microsoft.AspNetCore.Shared.Tests.csproj -v:q -p:UseIisNativeAssets=false --filter 'FullyQualifiedName~Certificate'— 12 passed.dotnet build src\Components\Testing\test\Microsoft.AspNetCore.Components.Testing.Tests.csproj -v:q -p:UseIisNativeAssets=false— passed.dotnet run --project src\Components\Testing\test\Microsoft.AspNetCore.Components.Testing.Tests.csproj --no-build -- -class Microsoft.AspNetCore.Components.Testing.Tests.ServerInstanceTests -noLogo— 11 passed.dotnet build src\Tools\dotnet-getdocument\src\dotnet-getdocument.csproj -v:q -p:UseIisNativeAssets=false— passed.dotnet build src\Tools\Microsoft.dotnet-openapi\src\Microsoft.dotnet-openapi.csproj --no-restore -v:q -p:UseIisNativeAssets=false— passed.dotnet build src\Middleware\Spa\SpaProxy\src\Microsoft.AspNetCore.SpaProxy.csproj -v:q -p:UseIisNativeAssets=false— passed.dotnet build src\Tools\dotnet-dev-certs\src\dotnet-dev-certs.csproj -v:q -p:UseIisNativeAssets=false— passed.dotnet build src\Tools\FirstRunCertGenerator\src\Microsoft.AspNetCore.DeveloperCertificates.XPlat.csproj -v:q -p:UseIisNativeAssets=false— passed.git diff --check 49147673007a4b1d676694e2c5f85b83ad76c36f..HEAD— passed.dotnet buildofMicrosoft.dotnet-openapi,Microsoft.AspNetCore.SpaProxy, andMicrosoft.AspNetCore.Components.Testing— passed;dotnet test src\Tools\Microsoft.dotnet-openapi\test\dotnet-microsoft.openapi.Tests.csproj -v:q -p:UseIisNativeAssets=false --filter 'FullyQualifiedName~OpenApiAddFileTests'— 11 passed.The exact pinned SDK and unchanged-main JavaScript bundles were shared as local prerequisites; C# builds and outputs were isolated by worktree. macOS/Linux certificate operations and parent monitoring, Windows/macOS SPA shutdown scripts, NativeAOT size, and full browser E2E behavior were not runtime-validated.
Related issue: none linked.