fix(probelink): retry bad-handshake/EOF dial errors — Android adb-forward race - #200
Merged
Conversation
…nnect adb forward accepts the host-side TCP connection before the device-side socket is plumbed, so a WebSocket upgrade attempted immediately after creating the forward fails with "websocket: bad handshake" (or EOF on a port with no device listener). Both errors were classified as fatal protocol errors, bypassing the retry loop entirely — the dial failed instantly regardless of --dial-timeout, while a manual connect a moment later succeeded. Bad handshake and EOF are now retried within the dial-timeout window. A genuine HTTP 401/403 token rejection from the agent is detected via the handshake response and still fails immediately, so stale tokens don't spin for the full timeout. Claude-Session: https://claude.ai/code/session_01BAhxxcGrCFAv6VWpgztLrF
…shake-retry # Conflicts: # CHANGELOG.md # internal/probelink/client.go # internal/probelink/client_test.go
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.
Summary
Fixes the reproducible Android connect race where
probefails instantly withwebsocket: bad handshakeright after creating its adb port forward, while a manual forward + connect a moment later always succeeds.Root cause: adb accepts the host-side TCP connection as soon as the forward exists, before the device-side socket is plumbed. A WebSocket upgrade attempted in that window dies mid-handshake, surfacing as
websocket: bad handshake(orEOFwhen nothing listens device-side) instead ofconnection refused.isTransientDialErrordidn't recognize either string, soDialWithOptionstreated them as fatal protocol errors and returned on the first attempt — bypassing the retry loop and ignoring--dial-timeoutentirely.Fix:
websocket.ErrBadHandshakeis now retried within the dial-timeout window, unless the handshake response is an HTTP 401/403 — a real token rejection still fails immediately with a clear "agent rejected token" error, so stale tokens don't spin for the full timeout.EOF/unexpected EOFadded to the transient-error list (also benefits the physical-iOS HTTP ping path, which sharesisTransientDialError).Test plan
go test ./internal/probelink/...— passesTestDialRetriesAfterBadHandshake— first upgrade attempt returns non-101, second succeeds; dial must retryTestDialRetriesAfterImmediateClose— TCP accept-then-close (adb with dead device side), then real server; dial must retryTestDialFailsFastOnAuthReject— 401 fails in <3s despite 30s dial timeoutTestIsTransientDialErrortable test incl. EOF variantsgo vet+go build ./...clean