Fix ToolTask EOF-truncation flake: drain on every wait slice + 30s budget (#13734)#13874
Closed
jankratochvilcz wants to merge 1 commit into
Closed
Conversation
…dget Addresses dotnet#13734 (ToolTaskCanChangeCanonicalErrorFormat regression to 22%). Under ChangeWave 18.6, WaitForProcessExit waited only 2s for the async stdout/stderr pipes to reach EOF after the process exited, and on timeout the data still buffered inside AsyncStreamReader was lost: the caller drains once after WaitForProcessExit returns, so anything the reader had not yet handed to our queues was never seen. Fix: 1. Replace the single 2s WaitAll with a 50ms-slice poll loop. 2. After every slice, call LogMessagesFromStandardError/Output to drain whatever the reader has already pushed onto the queues. By the time we return, the queues are caught up even if EOF was not reached. 3. Raise the outer budget to 30s -- still bounded for the grandchild-inherited-pipe case, but no longer racing CI pipe-flush latency. 4. On timeout, log a low-importance diagnostic (ToolTask.PipeEofTimeoutOnExit) so future occurrences are visible in the binlog. Verification: 5 consecutive runs x 4 previously regressing ToolTask_Tests x 2 TFMs = 60/60 passing. Full ToolTask_Tests (124 tests) green. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced May 27, 2026
Contributor
Author
|
Closing in favor of a test-only fix per maintainer feedback -- the blast radius of changing WaitForProcessExit for every ToolTask consumer is too high relative to the value of fixing one flake. Replacement PR will restructure the affected tests so the asserted lines are no longer the last lines of tool output (which is what the 2 s EOF race drops), plus add .Execute() return-value assertions, try/finally for the temp files, and diagnostic dumps on failure -- the 'Secondary improvements' list from #13734. |
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.
Implements the fix sketched in #13734 for the
ToolTaskCanChangeCanonicalErrorFormatflake. Latest survey (May 21-27 vs May 14-21) shows this test regressed from 15% to 22% failure rate despite the diagnostics PR #13830, so the underlying race is real and needs the structural fix the tracker has been proposing.Root cause (per #13734)
Under ChangeWave 18.6,
ToolTask.WaitForProcessExitdoes:Process.WaitForExit(timeout)does not wait on async pipes, so everything depends on the 2sWaitAll. The caller then drains the queues exactly once afterWaitForProcessExitreturns. On a busy CI runner, theAsyncStreamReaderthread can be context-switched out for >2s — the wait expires, the queues are flushed once, and anything the reader had not yet delivered is lost. Forcmd /C typeagainst a 2-line file, that finalBADTHINGHAPPENEDline is exactly what gets dropped.Fix
In
src/Utilities/ToolTask.cs::WaitForProcessExit:WaitAllwith a 50ms-slice poll loop.LogMessagesFromStandardError/Output). This is the key change: by the time we return, every line the reader has already pushed has been logged, even if EOF never arrives.ToolTask.PipeEofTimeoutOnExit) so the grandchild case is recognizable in the binlog without needing to repro.The change stays inside the existing
Wave18_6gate; no new wave needed. The legacy path is untouched.Risk
eofReached = trueand nothing else runs.Verification
dotnet build src/Utilities/Microsoft.Build.Utilities.csproj— clean, 0 warnings.dotnet test ... --filter-method "*ToolTask_Tests*"— 124/124 passing onnet48|x86andnet10.0|x64.ToolTaskCanChangeCanonicalErrorFormat,ErrorWhenTextSentToStandardError,OverrideStdOutImportanceToHigh,HandleExecutionErrorsWhenToolLogsError) × 2 TFMs = 60/60 passing.Local 100/100 repro coverage will follow before flipping out of draft; for now the goal is to get the change into CI so we can see whether the regressed
ToolTaskCanChangeCanonicalErrorFormatratio drops in next week's survey.Why draft
Want a few days of post-merge CI data on the regressed tests before declaring victory — per the flaky-test-survey skill, the PR landing is "a hypothesis, not a fix-confirming event." The tracker (#13734) stays open until the next survey cycle.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com