Repository navigation
Wait for cancelled aspire doctor checks to clean up DCP before exiting - #21917
Conversation
When the caller cancelled aspire doctor, EnvironmentChecker rethrew immediately, so the CLI could exit while DcpConnectionChecker was still killing the DCP process tree it started. That left DCP orphaned (sometimes SIGSTOPped) and holding the DCP state-store lock, which hung the next DCP in VS Code E2E runs. On caller cancellation, give the cancelled check up to 5 seconds to finish its cleanup before propagating the cancellation. Co-authored-by: Copilot <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21917Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21917" |
Tests selector2 / 101 PR test projects · 4 PR jobs, from 2 changed files. Selected PR test projects (2 / 101)
Selected PR jobs (4)
How these were chosen — grouped by what changed📦 affected project 🧪 Job reasons
Selection computed for commit |
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change that gives cancelled doctor checks a bounded window to release resources.
No open issues 🎉
What changed in this PR
This PR gives cancelled aspire doctor checks time to release resources before the CLI exits, reducing the risk of orphaned DCP processes blocking subsequent AppHost startup. It complements the process-monitoring protection in #21837.
Changes:
- Wait up to five seconds for the active check to finish cleanup before propagating caller cancellation.
- Add regression coverage for waiting on cleanup and enforcing the timeout when a check ignores cancellation.
| File | Description |
|---|---|
tests/Aspire.Cli.Tests/Utils/EnvironmentCheckerTests.cs |
Tests cleanup completion and bounded cancellation using fake time. |
src/Aspire.Cli/Utils/EnvironmentChecker/EnvironmentChecker.cs |
Adds a bounded cleanup wait on caller cancellation, leaving other timeout and error paths unchanged. |
Review effort: Balanced
…1919) ## Description **What failed:** the Linux VS Code E2E `deno-debugger` test *attaches js-debug to a Deno resource and hits a TypeScript breakpoint* flaked in runs [41354116968](https://github.com/microsoft/aspire/actions/runs/41354116968) and [41045515222](https://github.com/microsoft/aspire/actions/runs/41045515222). Each run starts with the extension's `aspire doctor` probes, and those probes leave DCP killed with exit code 137. ## Failure stats (14d, attempt 1) `CI` workflow on microsoft/aspire, runs created 2026-10-25 06:28 → 2026-11-08 06:28 UTC, **attempt 1 only**. Denominator: attempt-1 jobs that ran (success or failure). Hits: the failed job's log matches the signature. Jobs that lost their runner, which have no log, are excluded. Main runs have no reruns, so their flake check is the next main run of the job. | | | |---|---| | Signature | Deno test `attaches js-debug to a Deno resource and hits a TypeScript breakpoint` failing with `Failed to apply E2E control revision … E2E control command failed` | | Job | VS Code extension E2E (Linux, deno-debugger) | | main pushes: hits / runs | 0 / 153 (0.00%) | | main pushes, 30d: hits / runs | 0 / 265 (0.00%). The 16 days before the 14d window add 0 hits. | | PR runs: hits / runs | 3 / 814 (0.37%); 0 PR-caused excluded | | Combined rate | 3 / 967 = **0.31%** | | Flake check | PR: 3/3 rerun hits passed on rerun (0 never rerun) | | First / last hit | 2026-10-30 / 2026-11-05 | | Still hitting main? | Last main hit: never. 28 main runs since the last hit (2026-11-05), with 0 hits | | Fix evidence | Local: regression test fails before and passes 10/10 after (fake DCP server). No E2E repro. This PR's CI: Linux deno-debugger passed 1/1. | Failing attempt-1 jobs, most recent first (3 of 3 log-verified hits): | Date (UTC) | Branch | Job | Signature excerpt | |---|---|---|---| | [2026-11-05 21:25](https://github.com/microsoft/aspire/actions/runs/42112452711/job/127555522848) | `ievangelist-contextual-sidebar-states` | VS Code extension E2E (Linux, deno-debugger) | `Failed to apply E2E control revision 1793915466106: E2E control command failed.` | | [2026-11-01 21:51](https://github.com/microsoft/aspire/actions/runs/41354116968/job/124997289699) | `afscrome-wslc-container-tests-on-windows-ci` | VS Code extension E2E (Linux, deno-debugger) | `Failed to apply E2E control revision 1793571631482: E2E control command failed.` | | [2026-10-30 11:05](https://github.com/microsoft/aspire/actions/runs/41045515222/job/124040339568) | `mitchdenny-template-derived-defaults` | VS Code extension E2E (Linux, deno-debugger) | `Failed to apply E2E control revision 1793360300048: E2E control command failed.` | **Verdict: WEAK.** 3 hits, **never on main**, all passed on rerun. The signature is a generic E2E-control error matched only by message; nothing in the job log ties it to the DCP 415/kill path. Separately, 3 more failures of this test (`aspire new … exited with code 4`) were all on one PR branch and are a different failure. The 415 bug is real and worth fixing; the flake link is unproven. <!-- /failure-stats --> **Why:** `DcpConnectionChecker` sends its stop `PATCH /admin/execution` through `StringContent(..., Encoding.UTF8, "application/merge-patch+json")`, which puts `Content-Type: application/merge-patch+json; charset=utf-8` on the wire. DCP matches the media type exactly and answers **415**. The stop is never accepted, so disposal always runs `Kill(entireProcessTree: true)` on DCP. I reproduced this locally against a real DCP: the charset form returns 415, while the bare type returns 202 and DCP exits cleanly. **Fix:** - Send the bare `application/merge-patch+json` type. This is the same header `DcpKubernetesClient` already sends for this PATCH. - When DCP accepts the stop, wait up to the existing `s_processExitTimeout` (5s) for DCP to exit. Kill it only if it is still running after that. Refs #20839, which tracks the same test with an older signature, so this does not close it. This is separate from #21917, which covers cancellation cleanup in doctor. ## Confidence - New regression test `DcpConnectionHealthCheckTests.TestConnectionAsync_StopsDcpGracefullyInsteadOfKillingIt`. A minimal fake DCP API server returns 415 unless the Content-Type is exactly `application/merge-patch+json`. The test asserts that the doctor check passes, that it sends the exact media type and that the process is never killed. - **Before** the fix: fails with `Expected: "application/merge-patch+json"`, `Actual: "application/merge-patch+json; charset=utf-8"`. - **Content type fixed but no graceful wait:** fails with `KillCount` expected 0, actual 1. - **After** the fix: passes 10/10 in a loop. - `DcpConnectionHealthCheckTests`, `EnvironmentCheckerTests` and `DoctorCommandTests` pass 47/47 locally on Linux. - **Not run:** the VS Code extension E2E suite, and Windows/macOS. I did not re-run against a real DCP 0.27.3 after re-implementing; the earlier real-DCP 415/202 repro used 0.27.2. ## How we stop this recurring The new test pins the exact stop media type and the graceful no-kill path. If doctor regresses to killing DCP, the CLI unit tests fail and the problem no longer surfaces only as a downstream E2E flake. ## Checklist - Is this feature complete? - [x] Yes. Ready to ship. - [ ] No. Follow-up changes expected. - Are you including unit tests for the changes and scenario tests if relevant? - [x] Yes - [ ] No - Did you add public API? - [ ] Yes - [x] No - Does the change make any security assumptions or guarantees? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** Co-authored-by: davidfowl <[email protected]> Co-authored-by: Copilot <[email protected]>
Description
What failed: The VS Code extension AppHost edge-case E2E tests failed together on Linux (4 of 757 jobs in 7 days), for example 41200853091, 42151837629 and 42162155946. The AppHost's DCP log stops after
Started monitoring processand never reachesStarting controller manager, and then the tests fail withService e2e-terminal should have valid address.Failure stats (14d, attempt 1)
CIworkflow on microsoft/aspire, runs created 2026-10-25 06:28 → 2026-11-08 06:28 UTC, attempt 1 only. Denominator: attempt-1 jobs that ran (success or failure). Hits: the failed job's log matches the signature. Jobs that lost their runner, which have no log, are excluded. Main runs have no reruns, so their flake check is the next main run of the job.Service e2e-terminal should have valid addressFailing attempt-1 jobs, most recent first (3 of 3 log-verified hits):
sebros/resource-tag-position-storage-4a8108Service e2e-terminal should have valid address at this pointdamianedwards-launch-groupsService e2e-terminal should have valid address at this pointfix-21141-git-ls-files-drainVerdict: WEAK. 3 hits, never on main, all on unrelated PRs and all passed on rerun. The signature is matched only by its message; the link to the stopped DCP comes from logs, not CI. The underlying cleanup bug is real, but the flake attribution is thin.
Why: The extension cancels a background
aspire doctor.EnvironmentChecker.CheckAllAsyncrethrew caller cancellation immediately, so the CLI exited whileDcpConnectionCheckerwas still disposing its probe withKill(entireProcessTree). That kill SIGSTOPs the tree and then walks it. The failing CLI log showsTermination signal received39 ms afterDCP doctor stop request returned, with nowaiting for exitline. The probe's DCP was left orphaned and sometimes still SIGSTOPped while it held DCP's per-user state-store lock. The AppHost's DCP then blocked on that lock.Fix: On caller cancellation,
EnvironmentCheckernow waits for the cancelled check to finish cleaning up before it propagates the cancellation. The wait is bounded bys_cancelledCheckCleanupTimeout, a named 5-second constant with a why-comment. Timeout and other error paths are unchanged.Confidence
CheckAllAsync_CallerCancellationWaitsForCancelledCheckCleanup: the check's cleanup is blocked and the test asserts that the checker waits for it rather than completing. Paired runs: failed 5/5 without the fix and passed 5/5 with it.CheckAllAsync_CallerCancellationPropagatesnow uses a fake time provider to check that a check which ignores cancellation is abandoned after the 5-second bound, so cancellation still propagates.EnvironmentCheckerTests,DoctorCommandTests,DcpConnectionHealthCheckTests) pass locally on Linux: 47/47. Whitespace formatting checks pass.How we stop this recurring: The regression test fails if cancellation goes back to abandoning a check's cleanup. #21837 (
--monitor) complements this fix by covering abrupt CLI exits, but it can't help when DCP is SIGSTOPped. Follow-ups: fix the doctor stop request's HTTP 415 so DCP stops gracefully instead of being killed (handled separately), and ask DCP to bound its state-store lock wait.Refs #21600
Checklist
🤖 Posted by AspireAgent (AI Agent)