Skip to content

Fix flaky terminal WebSocket close handshake abort (ProducerDisconnect test) - #21500

Merged
Ankit Jain (radical) merged 1 commit into
mainfrom
aspireagent/fix-terminal-close-flake
Nov 10, 2026
Merged

Ankit Jain (radical) merged 1 commit into
mainfrom
aspireagent/fix-terminal-close-flake

Conversation

@davidfowl

Copy link
Copy Markdown
Collaborator

Description

Fixes an intermittent Windows failure in TerminalWebSocketTests.BrowserView_ProducerDisconnectClosesBrowserWhileWaitingForAcknowledgement(useGrpc: True). The test fails when the browser's CloseOutputAsync reply throws WebSocketException: The remote party closed the WebSocket connection without completing the close handshake (inner error: SocketException: An existing connection was forcibly closed).

No issue tracks this. It is a different test and a different root cause from #21471, which fixes the producer-side final-output drain in BrowserView_DrainsFinalOutputAndGraphicsBeforeDisconnect.

Evidence

  • Failure: main push run 41074175594, Dashboard (windows-latest) job 124127031025, sha 82d064c.
    • At 2.689s the server logged Timed out draining the final terminal frame (expected, because this test never acks).
    • At 5.305s it logged Terminal close handshake failed with TaskCanceledException at the close-reply wait.
    • The client's stack shows it called CloseOutputAsync as soon as ReadCloseAsync returned, so the browser received the Close after the server had already aborted.
  • Denominators (ci.yml attempt 1, Oct 16–30, from a partial survey of the window): the test failed in 1 of 56 completed Aspire.Dashboard.Tests Windows jobs and 0 of 56 Ubuntu jobs.
  • The test code and TerminalWebSocketProxy are unchanged between 82d064c and current main, and the test passes on later main runs. I also queued a rerun of the failed job on the same head.

Root cause

TerminalWebSocketProxy.CloseAsync sends Close and then waits for the browser's Close reply. It uses the same 2-second s_closeTimeout that bounds frame drain and sender teardown, and calls socket.Abort() when that expires.

In this test the browser is an in-process ClientWebSocket sharing the test host's thread pool. On a loaded Windows runner its reply can arrive more than 2 seconds after the server sends Close; the CI log shows about 0.6s of scheduling delay even before CloseAsync started. The server then resets the connection under the browser's in-flight reply.

Waiting for the reply only delays resource cleanup; the browser already has the authoritative close status. So the short drain budget is the wrong bound for this step.

Deterministic repro on main (Linux): delay the browser's Close reply by 3 seconds after ReadCloseAsync. It fails with the identical exception:

failed ...TerminalWebSocketTests.BrowserView_DelayedCloseReplyCompletesCloseHandshake (5s 869ms)
  WebSocketException : The remote party closed the WebSocket connection without completing the close handshake.
  ---- IOException : Unable to write data to the transport connection: Connection reset by peer.

Fix

  • Add a dedicated s_closeHandshakeTimeout (10s) for the Close reply wait in CloseAsync.
  • The 2-second s_closeTimeout still bounds the final-frame drain and sender teardown, so user-visible close latency is unchanged.
  • An unresponsive or disconnected browser is still aborted, and a socket error ends the wait immediately.

Validation

  • New regression test BrowserView_DelayedCloseReplyCompletesCloseHandshake: fails before the fix (above) and passes after.
  • Aspire.Dashboard.Tests.Terminal namespace: 113/113 passed.
  • Full Aspire.Dashboard.Tests: 2583/2583 passed.

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)

The dashboard aborted the browser socket if the browser's Close reply did
not arrive within the same 2 second budget used for draining frames. On a
loaded machine the reply can take longer, so the abort reset the TCP
connection under the in-flight reply (flaky
BrowserView_ProducerDisconnectClosesBrowserWhileWaitingForAcknowledgement
on Windows CI).

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

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 -- 21500

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 30, 2026 21:46
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

13 / 100 PR test projects · 2 PR jobs, from 2 changed files.

Selected PR test projects (13 / 100)

Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (2)

extension-e2e, native-dashboard-validation


How these were chosen — grouped by what changed

⚠️ 11 of the 13 selected test projects come from a single change — src/Aspire.Dashboard/Terminal/TerminalWebSocketProxy.cs.

🔧 src/Aspire.Dashboard/Terminal/TerminalWebSocketProxy.cs (changed source)
→ 11 via the project graph: Aspire.Dashboard.Components.Tests, Aspire.Hosting.Azure.Kubernetes.Tests (3 hops), Aspire.Hosting.Azure.Tests (2 hops), Aspire.Hosting.Blazor.Tests (2 hops), Aspire.Hosting.Dotnet.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests (2 hops), Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests (2 hops)

📦 affected project Aspire.Dashboard
→ 1 test: Aspire.Templates.Tests

🧪 tests/Aspire.Dashboard.Tests/Terminal/TerminalWebSocketTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Tests

Job reasons

Job Triggered by
extension-e2e • src/Aspire.Dashboard/Terminal/TerminalWebSocketProxy.cs
• affected project Aspire.Dashboard
native-dashboard-validation affected project Aspire.Dashboard

Selection computed for commit 54dbe31.

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 terminal WebSocket close-handshake timeout change.

No open issues 🎉

What changed in this PR

This PR addresses intermittent terminal WebSocket close-handshake failures in the Dashboard by allowing more time for a delayed browser reply. It is separate from the producer-output drain fix in #21471.

Changes:

  • Introduces a dedicated 10-second close-handshake timeout while retaining the 2-second final-frame drain and sender teardown limits.
  • Adds a regression test that delays the browser’s close reply by 3 seconds and verifies handshake completion and attachment cleanup.
File Description
tests/​Aspire.Dashboard.Tests/​Terminal/​TerminalWebSocketTests.cs Adds delayed close-reply regression coverage.
src/​Aspire.Dashboard/​Terminal/​TerminalWebSocketProxy.cs Separates the close-handshake timeout from shorter cleanup limits.

Review effort: Balanced

@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.

Copy link
Copy Markdown
Collaborator Author

CI on head 54dbe31 is green: 146 passed, 18 skipped.

Two attempt-1 failures were unrelated to this dashboard-only change. The CI bot auto-retried both once and both passed:

  • Hosting.Azure (ubuntu-latest): AzureFunctionsTests.AddAzureFunctionsProject_WorksWithMultipleProjects hit a TaskCanceledException timeout. This is in the excluded Azure Functions area.
  • VS Code extension E2E (Linux, java-apphost-debug-startup-timeout): the DCP AppHost failed to start ("Service orders should have valid address").

The original failing main job, Dashboard (windows-latest) on 82d064c, also passed when rerun on the same head (check run 124332096857). That confirms the failure is intermittent.


🤖 Posted by AspireAgent (AI Agent)

@radical Ankit Jain (radical) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed: no issues found.

@radical
Ankit Jain (radical) merged commit 9a91c4f into main Nov 10, 2026
326 of 330 checks passed
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → internal_refactor (bug fix for flaky test). No signals triggered. Changed files: src/Aspire.Dashboard/Terminal/TerminalWebSocketProxy.cs (internal WebSocket close-handshake handling, no new public surface/options/strings) and tests/Aspire.Dashboard.Tests/Terminal/TerminalWebSocketTests.cs (test only).

@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 10, 2026
Maddy Montaquila (maddymontaquila) added a commit that referenced this pull request Nov 13, 2026
…s, trace log previews, test flakes (#22232)

The remaining dashboard work for `release/17.0`, as one squashable PR:
one commit per change, in this order.

**Backported from `main` (cherry-picked with `-x`):**

1. #21500: Fix flaky terminal
WebSocket close handshake abort (test only)
2. #21503: Fix bUnit JS timeout
flakes in StructuredLogs/Traces/TraceDetails tests (test only)
3. #21471: Fix flaky
TerminalWebSocketTests final-output drain (test only)
4. #21924: Read resource row
state at every density in dashboard browser tests (test only)
5. #22142: Fix inconsistent
dashboard action icon colors. It conflicted with #22188 in
`ResourcesLayout.razor`: the resolution keeps the row menu on every row,
parameters included, with #22142's icon color.

**From open PRs against `main`, applied as they stand:**

6. #22228: Fix resource sidebar
hover state after selection
7. #22229: Keep resource picker
popup width consistent

**New:**

8. Render the trace log preview only for the marker that's hovered or
focused. Each log marker rendered its own hidden preview for the
tooltip, so a span with many logs built over a million hidden elements.
The page now renders one preview, filled on hover or focus. This
addresses Copilot's review on #22230.

9. Center tag group chevrons over the state dot column. In the compact
sidebar at rest, the rows' state dots form a column at the end of the
list, and the group header's chevron sat 13px past it. This replaces
#21996.
10. Fix two resource pane Playwright tests:
- `Rows_KeepDensity` expected parameter rows in the expanded list to
have no overflow menu, but every row has one now.
- `FilterAndGrouping` could hover before the feedback prompt pushed the
page down 40px, leaving the pointer on the brand. It now waits for the
prompt.

When `release/17.0` merges back into `main`, the `Rows_KeepDensity`
change has to come along with it, because #22228's version of that test
expects no menu on parameter rows.

Once this is in `release/17.0`, `release/17.0` merges back into `main`.
#22228 and #22229 can then close on `main`.

## Customer Impact

Fixes and polish to the 17.0 dashboard: icon colors, the resource
sidebar and picker, and trace pages with many logs.

## Testing

- `Aspire.Dashboard.Components.Tests`: 1,447 passed, 0 failed.
- `ResourcePaneResponsiveTests.FilterAndGrouping_*` and
`Rows_KeepDensity*`: 11 passed. `FilterAndGrouping` passed 5 runs in a
row after the fix; before it, the 2000px cases failed in about half the
runs.
- The chevron alignment was checked in the browser at 1440px: the
chevron and the dots are both centered 25px from the list's end.

## Risk

Low. Dashboard-only, and the backports are unchanged apart from the one
conflict described above.

## Regression?

No.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: David Fowler <[email protected]>
Co-authored-by: davidfowl <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Maddy Montaquila <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: James Newton-King <[email protected]>
Co-authored-by: Sébastien Ros <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-terminal Terminal/PTY support — TerminalHost, WithTerminal, dashboard terminal view flaky-test needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants