fix(forward): reconnect automatically after device replug (ios forward) - #804
Open
danielpaulus wants to merge 2 commits into
Open
fix(forward): reconnect automatically after device replug (ios forward)#804danielpaulus wants to merge 2 commits into
danielpaulus wants to merge 2 commits into
Conversation
ios forward captured the numeric usbmux device id once at startup. usbmuxd assigns a fresh id every time a device is plugged in, so after a disconnect/reconnect every new client connection failed with 'could not connect to phone' while iproxy kept working in the same session. Each accepted client connection still dials with the captured id first; when that connect fails, the device is looked up again by udid (the serial survives a replug) and the connect is retried once with the fresh id. The retry seam is an injected resolver func, so the behavior is unit-tested device-free against a fake usbmuxd on a temp unix socket. Also closes the usbmux socket on a failed Connect instead of leaking it. The exported StartNewProxyConnection signature is unchanged. Fixes #378 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk
Owner
Author
|
/test-devices |
Contributor
Contributor
|
❌ Real-device tests failed — see run. |
Register the temp-dir removal with t.Cleanup immediately after MkdirTemp so a subsequent net.Listen failure (which t.Fatalf's) can no longer leak the directory. Split the listener close into its own cleanup so ordering stays correct (listener closed before its dir is removed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk
Owner
Author
|
Adversarial review (with codex cross-check). Verdict: ship-worthy, one small test-hygiene fix pushed to this branch. Fix applied (
Reviewed, no change needed
Dismissed (codex flagged, not a bug)
Verified: |
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.
Problem
ios forward <hostPort> <phonePort>stops working after the device is unplugged and plugged back in. Every new client connection fails withcould not connect to phoneuntil the forward process is restarted.iproxyfrom libimobiledevice handles a replug in the same session.Root cause
Forward()captures the numeric usbmuxDeviceIDonce at startup and every proxied connection dials usbmuxd with it (forward.go, previously line 95-97). usbmuxd assigns a new device id each time a device is plugged in, so after a replug the captured id is stale and everyConnectrequest is answered with a mux error. The device's udid (serial) is stable across replugs — only the numeric id changes.Fix
resolveDeviceIDfunc (backed byios.GetDevice(udid)), and the connect is retried once with the fresh id.Connectfails (previously it leaked on that path).StartNewProxyConnectionkeeps its signature and behavior (no resolver); the resolver is wired in byForward().Options considered
ListDevicesround trip to every connection even when nothing changed.Test plan
Device-free unit tests (
ios/forward/forward_reconnect_test.go) run a minimal fake usbmuxd on a temp unix socket (USBMUXD_SOCKET_ADDRESS) that rejects a stale id with mux error 2 and echoes bytes for the current id:TestStaleDeviceIDIsReResolved— reproduces ios forward not reconnecting automatically if device disconnected and reconnected #378: stale id triggers exactly one re-resolve, and bytes flow end-to-end afterwards. Does not compile/pass without this change.TestCurrentDeviceIDConnectsWithoutResolve— happy path never invokes the resolver.TestStaleDeviceIDWithoutResolverFails— pins the exportedStartNewProxyConnectionbehavior: stale id fails and the client conn is closed.go build ./...,go test -race ./...andgofmt -lare clean.Fixes #378
🤖 Generated with Claude Code
https://claude.ai/code/session_01J8eMENxJ1nec9CeHp4tjWk