Skip to content

Wait for cancelled aspire doctor checks to clean up DCP before exiting - #21917

Merged
Adam Ratzman (adamint) merged 1 commit into
mainfrom
aspireagent/doctor-cancel-dcp-cleanup
Nov 25, 2026
Merged

Adam Ratzman (adamint) merged 1 commit into
mainfrom
aspireagent/doctor-cancel-dcp-cleanup

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

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 process and never reaches Starting controller manager, and then the tests fail with Service e2e-terminal should have valid address.

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 Service e2e-terminal should have valid address
Job VS Code extension E2E (Linux, edge-cases)
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 / 812 (0.37%); 0 PR-caused excluded
Combined rate 3 / 965 = 0.31%
Flake check PR: 3/3 rerun hits passed on rerun (0 never rerun)
First / last hit 2026-10-31 / 2026-11-06
Still hitting main? Last main hit: never. 20 main runs since the last hit (2026-11-06), with 0 hits
Fix evidence Local: regression test 5/5 fail → 5/5 pass. A real CLI+DCP SIGTERM repro leaked DCP 10/18 → 0/18, but it ran against an earlier version of the change. This PR's CI: Linux edge-cases passed 2/2 attempts on the head commit.

Failing attempt-1 jobs, most recent first (3 of 3 log-verified hits):

Date (UTC) Branch Job Signature excerpt
2026-11-06 04:22 sebros/resource-tag-position-storage-4a8108 VS Code extension E2E (Linux, edge-cases) Service e2e-terminal should have valid address at this point
2026-11-06 02:40 damianedwards-launch-groups VS Code extension E2E (Linux, edge-cases) Service e2e-terminal should have valid address at this point
2026-10-31 12:23 fix-21141-git-ls-files-drain VS Code extension E2E (Linux, edge-cases) `Service e2e-terminal should have valid address at this point
at Aspire.Hosting.Dcp`

Verdict: 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.CheckAllAsync rethrew caller cancellation immediately, so the CLI exited while DcpConnectionChecker was still disposing its probe with Kill(entireProcessTree). That kill SIGSTOPs the tree and then walks it. The failing CLI log shows Termination signal received 39 ms after DCP doctor stop request returned, with no waiting for exit line. 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, EnvironmentChecker now waits for the cancelled check to finish cleaning up before it propagates the cancellation. The wait is bounded by s_cancelledCheckCleanupTimeout, a named 5-second constant with a why-comment. Timeout and other error paths are unchanged.

Confidence

  • New regression test 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_CallerCancellationPropagates now uses a fake time provider to check that a check which ignores cancellation is abandoned after the 5-second bound, so cancellation still propagates.
  • Related suites (EnvironmentCheckerTests, DoctorCommandTests, DcpConnectionHealthCheckTests) pass locally on Linux: 47/47. Whitespace formatting checks pass.
  • An earlier investigation reproduced this with the real CLI and DCP by sending SIGTERM 0–10 ms after the stop request on a loaded machine. Before the fix, DCP leaked in 10 of 18 runs, 3 of them SIGSTOPped. After the fix, it leaked in 0 of 18. That repro was run against an equivalent earlier version of this change; I did not rerun it for this commit.
  • Not run: the VS Code extension E2E suite and Windows/macOS locally (left to CI). The link between the stopped DCP and the state-store lock in CI comes from the logs plus a separate lock repro; it was not observed directly in CI.

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

  • 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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

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]>
@davidfowl David Fowler (davidfowl) added the agent:working An AI agent is actively working on this issue or PR label Nov 8, 2026 — with Copilot SWE Agent
@github-actions

github-actions Bot commented Nov 8, 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 -- 21917

Or

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

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Tests selector

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

Selected PR test projects (2 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

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

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

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Utils/EnvironmentChecker/EnvironmentChecker.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit f183ed6.

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.

🟢 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

@adamint
Adam Ratzman (adamint) merged commit fe4ce3a into main Nov 25, 2026
440 of 443 checks passed
Adam Ratzman (adamint) pushed a commit that referenced this pull request Nov 25, 2026
…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]>
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 25, 2026
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.

3 participants