Skip to content

test(tui): wait for the stuck request to be accepted before stopping - #5437

Merged
kovtcharov-amd merged 1 commit into
mainfrom
fix/tui-stop-budget-race
Oct 20, 2026
Merged

kovtcharov-amd merged 1 commit into
mainfrom
fix/tui-stop-budget-race

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The macOS TUI test job fails intermittently on TestStopGivesUpOnAStuckRequestAtItsBudget (twice on #5148 today), which blocks unrelated PRs. The test could call Stop before the control server had even accepted its half-written request, so Stop found nothing in flight and returned success at once. The test now waits for a later /status request to be answered first, which proves the earlier connection was accepted.

Test plan

  • go test ./internal/control/ -run TestStopGivesUpOnAStuckRequestAtItsBudget -count=30 passes
  • go test ./internal/control/ passes
  • TUI Build & Test (macos-latest, -race) green

TestStopGivesUpOnAStuckRequestAtItsBudget failed on macOS -race when Stop
ran before the server had accepted the half-written request: with nothing
tracked, Shutdown returned nil at once. Answering a later /status request
first proves the earlier connection was accepted.
@github-actions github-actions Bot added the tui Go terminal UI (gaia-tui) label Oct 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

This fixes a flaky macOS TUI test: before, it could call Stop before the server had picked up the half-sent request, so Stop returned right away and the test failed. Now the test sends one ordinary request and waits for the reply before calling Stop, which proves the stuck request was already picked up. The reasoning holds and the change touches only the test.

Real-world evidence

N/A: this is a test-only change, so no evidence bundle was produced. I ran the changed test here with the race detector, 20 times in a row (go test ./internal/control/ -run TestStopGivesUpOnAStuckRequestAtItsBudget -count=20 -race), and it passed. The macOS CI job is still the real check.

🔍 Technical details

Why the fix is sound

  • net.Dial returns only after the TCP handshake, so the half request's connection is already in the kernel accept queue before the follow-up dial. The server accepts connections in that order.
  • http.Server.Serve registers each accepted connection as StateNew synchronously, before it accepts the next one. So once the follow-up /status is answered, the stuck connection is being tracked.
  • Shutdown treats a StateNew connection younger than 5s as active. Stop therefore waits out the 200 ms budget and returns the expected deadline error.
  • http.DefaultClient leaves the follow-up connection idle in its keep-alive pool. Shutdown closes idle connections at once, so that connection doesn't change the timing.

Issues found: none.

Strengths

  • The fix waits on an event (the reply) rather than adding a time.Sleep.
  • The one-line comment explains why the warm-up request is there, not what it does.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit f206194 Oct 20, 2026
50 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/tui-stop-budget-race branch October 20, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tui Go terminal UI (gaia-tui)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant