carlos / platform Public

Ledger · fix-tunnelclient-upgrade-flake

Human

<task-notification> <task-id>ab46481cf8ef67664</task-id> <tool-use-id>toolu_012rqpLi4wxJ8eCVvM9eLQP3</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/ab46481cf8ef67664.output</output-file> <status>completed</status> <summary>Agent "Fix tunnelclient upgrade test flake" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>The flake was in the test, not in the code. `RoundTripUpgrade` and `UpgradeConn` reset the stream correctly on every run. The fix is one test-only commit, pushed to origin, and CI is running. **Root cause.** The subtest cancelled the context once the hub had received the box's marked 200, and assumed the box's `Hijack` had already returned by then. With x/net v0.60.0 that isn't guaranteed: - In `serverConn.wroteFrame`, x/net answers the flush's wait (`replyToWriter`) before the scheduler flushes the 200 onto the wire. - The handler's `Hijack` → `Flush` then waits in `writeHeaders` (server.go:2376-2385), which selects on that answer and on `st.cw`, the stream-closed signal. - If the handler goroutine hadn't been scheduled yet, the 200 could reach the hub, the hook fire, the test cancel, and the hub's RST_STREAM be processed, all before that select ran. Both cases were then ready and Go picks one at random. Picking `st.cw` makes `Hijack` fail with "http2: stream closed". - When that happens, the test box handler logs `t.Errorf` at :65 and returns before `boxReadErr`. Nothing ever arrives on `readErr`, so `wantReset` times out at :555. **Why it isn't a production defect.** The hub sent the reset on every run, and the "stream closed" error is the box seeing that reset. It just sees it in `Hijack` rather than in the conn's `Read`. On a real box, the edge's reverse proxy treats a failed hijack as an error and closes the app connection, which is the right outcome. The hub still returns `ErrUpgradeHandshake` wrapping `context.Canceled`. **Fix** (`internal/tunnelclient/upgrade_hub_test.go` only): - `boxEnd` has a new `hijacked` channel, which `hijackingBox` closes once `Hijack` returns. - The "during the handshake" subtest now waits for that event as well as `hookHandshake` before it cancels. If the box handler returns without hijacking, the test fails at once. No timer decides the order. **Test results** (nice 19): | Run | Original test | Fixed test | |---|---|---| | Subtest, -count=200, no -race | 88 of 200 failed | 200/200 passed | | Subtest, -count=200, -race | 0 failed | 200/200 passed | - The -race row isn't a useful comparison: the race detector shifts scheduling enough that the original also passed 200/200 there. Without -race it fails reliably. - `TestRoundTripUpgradeEndsWithItsContext` also passed at -count=500 with -cpu=1,2,4,8. - The whole package passed with -race at -count=1, and without it at -count=20. `go vet` is clean. **Not run:** no non-test code changed, so the brief didn't call for the darwin/arm64, windows/amd64 and linux/arm64 builds or `make census-card`. The census card is unchanged and there was nothing to propose. **Commit and push:** `e9b3bc3b` "Fix the #471 tunnelclient flake in TestRoundTripUpgradeEndsWithItsContext/during_the_handshake (test only, no production defect)…", ending with the Co-Authored-By line. Pushed to origin (amadan) as `fix-tunnelclient-upgrade-flake`; the remote tip is `e9b3bc3b002f2c4f3617e3c88e51d3fca8704b6f`. **CI:** `amadan ci status` reports "CI running" at e9b3bc3b0. I didn't wait for it. **One other test has the same weakness, unfixed:** the "nothing within the deadline" case in `TestRoundTripUpgradeRefusesBadInBand101`. There the hub resets after its 200 ms handshake timeout. It would only fail if the box handler went unscheduled for 200 ms, so I left it alone; I didn't see it fail. The Go commands needed the sandbox off, because inside it the default Go cache is read-only. GOCACHE stayed at its default, no processes were left running, and the one scratch file I made in `$TMPDIR` is deleted.</result> <usage><subagent_tokens>80942</subagent_tokens><tool_uses>20</tool_uses><duration_ms>292700</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>bzxc10tw5</task-id> <tool-use-id>toolu_01HTUtb1FETnazxKAPRzM9HK</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/bzxc10tw5.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on the flake fix branch" completed (exit code 0)</summary> </task-notification>