Skip to content

Prevent aspire doctor from orphaning DCP processes - #21837

Merged
Karol Zadora-Przylecki (karolz-ms) merged 9 commits into
mainfrom
dev/karolz/doctor-dcp-cleanup
Nov 25, 2026
Merged

Karol Zadora-Przylecki (karolz-ms) merged 9 commits into
mainfrom
dev/karolz/doctor-dcp-cleanup

Conversation

@karolz-ms

Copy link
Copy Markdown
Contributor

Description

aspire doctor starts short-lived DCP API servers to check connectivity. If the CLI exits abruptly, managed cleanup cannot run and those API servers and their controllers can outlive the command. Bind each probe's DCP lifetime to the executing CLI process so DCP shuts down when its owner exits.

  • Pass --monitor <CLI PID> through the common launch path for both certificate modes, preserving normal shutdown, cancellation, and error cleanup.
  • Let DCP capture its native process identity rather than supplying a .NET wall-clock start time; DCP uses a boot-relative identity on Linux.
  • Add real-DCP regressions for abrupt parent exit and normal probe completion while the parent remains alive, plus focused argument, certificate, cancellation, and failure coverage.
  • Keep the regression's standard streams usable after its disposable parent exits, so Go's broken-pipe behavior cannot falsely satisfy the lifetime assertion.

The test project restores the repository-pinned native DCP package. Production dependency versions and shared process infrastructure are unchanged.

User-facing usage

Existing invocations and diagnostic output are unchanged:

aspire doctor --format json

The lifetime guard is automatic; it does not introduce a new Aspire CLI option.

Validation

Passed on macOS ARM64 with Podman selection: 53 passed, 1 existing Linux-only test skipped, 0 failed.

ASPIRE_CONTAINER_RUNTIME=podman \
ASPIRE_CLI_NUGET_SERVICE_INDEX=https://packagefeedproxy.microsoft.io/nuget/v3/index.json \
MSBUILDTERMINALLOGGER=false \
dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj \
  --no-launch-profile -- \
  --filter-class '*.DcpConnectionHealthCheckTests' \
  --filter-class '*.DcpConnectionLifetimeTests' \
  --filter-class '*.DoctorCommandTests' \
  --filter-class '*.NativeCertificateToolRunnerTests' \
  --filter-not-trait 'quarantined=true' \
  --filter-not-trait 'outerloop=true'
  • Negative control: the finished parent-exit regression fails when only the monitor arguments are removed, then passes when restored. Test-owned API servers, controllers, and temporary session directories were confirmed cleaned up.
  • Repository whitespace-format verification and git diff --check passed.
  • The production test selector attributed all seven changed paths and selected the existing CLI test consumers; no routing changes were required.
  • Windows/Linux execution and remote CI execution have not been performed.
  • An expanded generic process-fixture run was stopped after readiness-handshake timeouts; it is not counted as passed. The shared process fixture remains unchanged.
  • Restore/build emitted existing NU1903 warnings for the repository-pinned ILCompiler; no SDK or dependency version was changed to suppress those unrelated warnings.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21837

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21837"

@github-actions

This comment has been minimized.

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

Only macOS ARM64 execution is reported, leaving platform-specific parent-exit monitoring, .NET 11 standard-handle inheritance, and cleanup behavior unvalidated on Windows and Linux.

No open issues 🎉

What changed in this PR

This PR ties aspire doctor’s short-lived DCP processes to the CLI process so they shut down after an abrupt CLI exit, without changing command options or diagnostic output.

Changes:

  • Passes --monitor <CLI PID> through the shared DCP launch path for both certificate modes.
  • Adds real-DCP regressions for abrupt parent exit and normal probe cleanup, with file-backed output to avoid broken-pipe false positives.
  • Expands certificate, cancellation, and failure coverage, shares the certificate test helper, and restores the pinned native DCP package for tests.
File Description
tests/​Aspire.Cli.Tests/​Utils/​DcpConnectionLifetimeTests.cs Tests DCP shutdown after parent exit and normal probe completion.
tests/​Aspire.Cli.Tests/​Utils/​DcpConnectionHealthCheckTests.cs Adds monitor-argument, certificate, cancellation, and failure coverage.
tests/​Aspire.Cli.Tests/​TestServices/​TestCertificateManager.cs Extracts a shared certificate helper with configurable trust.
tests/​Aspire.Cli.Tests/​TestServices/​DcpConnectionTestProcess.cs Provides controlled real-DCP execution with persistent standard streams.
tests/​Aspire.Cli.Tests/​Certificates/​NativeCertificateToolRunnerTests.cs Reuses the shared certificate helper.
tests/​Aspire.Cli.Tests/​Aspire.Cli.Tests.csproj Restores native DCP and exposes its directory to tests.
src/​Aspire.Cli/​Utils/​EnvironmentChecker/​DcpConnectionChecker.cs Adds CLI process monitoring to DCP connectivity probes.

Review effort: Balanced

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 Windows controller-path comparison does not account for differing path separators, causing valid controller records to be rejected and both lifetime tests to time out.

1 open issue

Review effort: Max

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

This comment has been minimized.

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 test controller can use the user's real DCP state database, risking mutation of real state and deletion of persistent-process records and logs.

4 open issues
1 resolved since last review

Review effort: Max

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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

Human assessment is needed because the test’s outer timeout may cause false failures on slow runners while startup and readiness remain within their individual limits.

No open issues 🎉

4 resolved since last review

Review effort: Max

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

Exceptional teardown paths can swallow caller cancellation, and the tests do not verify that an accepted stop request shuts down DCP without invoking Kill.

2 open issues
1 resolved since last review

Review effort: Max

Consolidate the fake DCP API server into the shared test service and
pass the temporary storage required by main's centralized allocation.

Co-authored-by: Copilot App <[email protected]>
@github-actions

This comment has been minimized.

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 cleanup timeout can let aspire doctor exit before teardown finishes, while failing probes can return failure instead of propagating caller cancellation.

3 open issues

Review effort: Max

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

4 / 101 PR test projects · 6 PR jobs, from 13 changed files.

Selected PR test projects (4 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Hosting.Native.Core.Tests, Aspire.Hosting.RemoteHost.Tests

Selected PR jobs (6)

cli-starter-validation, extension-e2e, homebrew-installer, polyglot, typescript-api-compat, winget-installer


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

📦 affected project Aspire.Hosting.Native.Server
→ 1 test: Aspire.Cli.EndToEnd.Tests

🔧 src/Aspire.Hosting.Native.Server/Dcp/DcpApiClient.cs (changed source)
→ 1 via the project graph: Aspire.Hosting.Native.Core.Tests

🧪 tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Certificates/NativeCertificateToolRunnerTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/DcpConnectionTestProcess.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/FakeDcpApiServer.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/TestCertificateManager.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/TestServices/TestProcessExecutionFactory.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Utils/DcpConnectionHealthCheckTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Aspire.Cli.Tests/Utils/DcpConnectionLifetimeTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

🧪 tests/Shared/Processes/ChildProcessTests.cs (changed test)
→ 1 via the project graph: Aspire.Hosting.RemoteHost.Tests

Job reasons

Job Triggered by
cli-starter-validation • affected project Aspire.Hosting.Native.Server
• affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Utils/EnvironmentChecker/DcpConnectionChecker.cs
• affected project Aspire.Hosting.Native.Server
• affected project Aspire.Cli
homebrew-installer affected project Aspire.Hosting.Native.Server
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli
winget-installer affected project Aspire.Hosting.Native.Server

Selection computed for commit 021b288.

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

Human review is needed because the regression test’s five-second completion timeout may fail valid shutdowns that can take up to fifteen seconds.

2 open issues
1 resolved since last review

Review effort: Max

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Skipped: proven false positive. Triggered signals: pr_body_has_cli_flag_mention (evidence: the PR body mentions --monitor <CLI PID>) and pr_body_has_user_facing_section (evidence: the "User-facing usage" heading in the PR body).

  • --monitor is an internal argument that aspire doctor passes to DCP, not an Aspire CLI option.
  • The PR body states that existing invocations and diagnostic output are unchanged and that no new CLI option is introduced.
  • The change is an internal lifetime guard that prevents orphaned DCP processes, plus tests. It adds no user-visible behavior, configuration, or public API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants