Repository navigation
[release/17.0] Keep captured output when ProcessCaptureRunner's post-exit drain bound expires - #22047
Closed
Mitch Denny (mitchdenny) wants to merge 1 commit into
Conversation
…d expires (#21556) ## Description `PeerInstallProbeTests.ProbeAsync_PeerEmitsArrayWithNonObjectFirstElement_FallsBackToVersion("[\"string\"]")` failed once on Windows with `Peer produced no usable output (and --version fallback)`. That run was [35003412018 / job 104497909578](https://github.com/microsoft/aspire/actions/runs/35003412018/job/104497909578). The test took **4.3s**. Passing runs take a median of 0.154s and a max of 0.51s (n=60, from TRX of 15 recent main Cli-windows runs, 300/300 PeerInstallProbe passes). ### Root cause `ProcessCaptureRunner.RunAsync` handles a process that exits normally like this: - It waits up to a fixed 2s (`s_postExitCaptureWaitBound`) for the stdout/stderr capture to reach EOF. - If that bound expires, `SwallowCaptureAsync` returns **`createEmptyCapture()`**. That throws away everything the reader had already buffered. Only after that does it cancel the reads. So a peer that printed `9.0.0` and exited 0 could come back as exit 0 with empty stdout. `ExtractVersionLine` then returns null and the probe reports "no usable output". EOF arrives late when a descendant still holds the inherited pipe handle, or when reader continuations are delayed under CI load. The extra 2s matches the 4.3s failure duration. The probe's Debug diagnostics, such as "Timed out waiting 2s for process output capture", were missing from the CI log. The test's `LoggerFactory` used the default Information minimum level, so they were filtered out before reaching the xunit provider. ### Fix When the post-exit drain bound expires, `RunAsync` now cancels the reads and *then* collects the capture, waiting at most the 250ms post-kill bound. It no longer abandons the capture. The result carries the real exit code, the capture, and a new `ProcessCaptureFailureKind.OutputDrainTimedOut`: - `PeerInstallProbe` treats `OutputDrainTimedOut` as success. `ReadCappedAsync` returns partial output on cancellation, so the version the peer wrote before exiting is kept. The existing parsers still reject unusable output. - `GitCommandRunner` and `ConfigurationHelper` reject any non-null `FailureKind`, so an incomplete drain still fails as before (`RepositoryUnavailable` / settings write refused). This keeps `ConfigSourceServiceGitTests.RunProcess_DescendantHoldingOutputCannotBlockShutdown` passing. The first revision, without the flag, broke that test in CI, which is why the flag exists. - The happy path doesn't change. The final `timeoutCts.Cancel()` still guarantees no capture task outlives the call. I also changed the test logger factory to `SetMinimumLevel(LogLevel.Trace)` so future failures include the probe's Debug logs. ### Regression test and evidence The new test is `ProbeAsync_VersionFallbackDescendantHoldsStdoutOpen_KeepsCapturedVersion` (POSIX only). The fake peer: - fails `doctor`; - on `--version`, prints `9.0.0`, leaves a background `sleep 60 &` that inherits stdout, and exits 0. This makes the late-EOF condition deterministic. The test runs real processes through the real `ProcessCaptureRunner`; nothing is mocked. | | Result | |---|---| | Before fix (Linux) | **Fails** after 2.1s. The log shows `Timed out waiting 2s for process output capture` and the probe returns no version. | | After fix (Linux) | **10/10 pass**, about 2.08s each (the expected drain bound, then cancellation). | | `PeerInstallProbeTests`, `ConfigSourceService*`, `GitCommandRunner*`, `ConfigurationHelper*` and `ProcessCaptureRunner*` classes, after fix | 340 total: 339 passed, 1 skipped (Windows-only), 0 failed. These run real `git` and real descendant processes. | | New test plus `RunProcess_DescendantHoldingOutputCannotBlockShutdown`, repeated | 5 × 5 = 25/25 passed | **Caveat:** the Windows failure left no probe diagnostics, so I can't prove the late EOF from that one log. One alternative remains possible: the fake peer's `echo %* | findstr` failing transiently, which exits 127 and produces the same message. The 2s-shaped extra duration points to the drain path, and the fix closes that path either way. Fixes #20147 ## 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 - Does the change require an update in our Aspire docs? - [ ] Yes - [x] No **🤖 Posted by AspireAgent (AI Agent)** --------- Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 1664086)
14 tasks
This comment has been minimized.
This comment has been minimized.
Mitch Denny (mitchdenny)
marked this pull request as ready for review
November 10, 2026 05:15
Mitch Denny (mitchdenny)
requested review from
James Newton-King (JamesNK) and
David Fowler (davidfowl)
as code owners
November 10, 2026 05:15
Member
Author
|
Approved for inclusion in release/17.0. Do not merge yet. |
Mitch Denny (mitchdenny)
force-pushed
the
mitchdenny-backport-17-0-49-pr21556
branch
from
November 10, 2026 08:05
3e09a4d to
7096a14
Compare
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22047Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22047" |
This comment has been minimized.
This comment has been minimized.
Mitch Denny (mitchdenny)
force-pushed
the
mitchdenny-backport-17-0-49-pr21556
branch
from
November 10, 2026 08:28
7096a14 to
3e09a4d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Backport of #21556 to
release/17.0(cherry-picked from 1664086 with no modifications).Layer 49 of 55 in the release/17.0 backport stack; stacked on #22046.
Backport recommendation: Yes — CLI could lose captured process output under load.
Validation: Stable patch IDs match (
1bc7687e0725ac8735235468f57cdf45c479e9b3). Builds/tests not run for this unchanged cherry-pick.Backport of #21556
Checklist
<remarks />and<code />elements on your triple slash comments?