Repository navigation
fix(tcpip): resolve tcpip() and usb() unless adbd replies with an error - #583
Merged
Merged
Conversation
device.tcpip() and device.usb() expected adbd's "restarting in ..." message after OKAY and otherwise threw an Error with the output as its message. adbd restarts right after writing that message, and sometimes it doesn't reach the host, although the switch happened. Both methods then rejected with an empty Error. On Android 30 and 36 emulators this happened in 6 of 16 calls on master. No output now counts as success, as it does for adb itself, which ignores the output. Any other message, such as "invalid port 0", is still an error with that message. usb() had the same code and gets the same fix. Fixes #527 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Karol Wrótniak <[email protected]>
adbd writes its "restarting in ..." line and restarts, so the line can
be cut off anywhere, and a reply such as "restar" still rejected. Any
output now counts as success except adbd's own error reply: in adbd's
restart_service.cpp, tcpip: with a port <= 0 answers
"invalid port <port>" ("invalid port" before Android 5), and usb: has
no error reply. A port that isn't a number makes the service fail,
which arrives as a FAIL and is already handled.
tcpip.ts and usb.ts now share the check in restartreply.ts.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Karol Wrótniak <[email protected]>
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
device.tcpip()resolved only if adbd's output afterOKAYmatchedrestarting in; anything else becamenew Error(output.trim()). adbd writes its message and restarts right away, and sometimes the message doesn't reach the host, even though the switch happened.tcpip()then rejected with an emptyError.device.usb()has the same code and the same bug.Raw
tcpip:5555andusb:replies on the emulators, read straight from the adb server socket:tcpip:55553 of 3 timesOKAY+"restarting in TCP mode port: 5555\n";usb:OKAY+ empty payload, althoughservice.adb.tcp.portwent to0.tcpip:55553 of 3 times the message;usb:OKAY+"restarting in USB mode\n".master
device.tcpip(5555)thendevice.usb(), 4 rounds on each emulator, checkinggetprop service.adb.tcp.portafter each:That's 6 failures in 16 calls (
tcpip()2 of 8,usb()4 of 8), each time after the switch had actually happened.Fix
Any output counts as success, matching
adb tcpip/adb usb, which ignore the output, unless it's one of adbd's own error replies. adbd writes its message and restarts, so the message can be cut off anywhere ("restar") or be missing entirely. tcpip.ts and usb.ts share the check inrestartreply.ts.Which outputs are errors comes from adbd's source:
daemon/restart_service.cpp(main):tcpip:with a port <= 0 writesinvalid port %d.services.c: the same case writesinvalid port.usb:has no error reply.services.cpp: a port that isn't a number makes the service fail to start, which arrives as a FAIL and is already handled.adbd has no
error: …reply for these services, so only^invalid portis matched.Fixes #527
Verification
tcpip→ the port,usb→true), and adbd'sinvalid port 0rejects with that message.npm test: 287 passing.npm run lintis clean.service.adb.tcp.portwas5555after eachtcpip()and0after eachusb(), on both emulators.device.tcpip(0)rejects with"invalid port 0"on both API levels.tcp.port=0) afterwards.stf doesn't use
tcpip()orusb().Review follow-up (commit
57ecac9)restarorrestarting in TCP mode ponow resolves instead of rejecting. Onlyinvalid port …rejects. Reasoning above.restartreply.ts.invalid portreply for tcpip; a cut-offrestarting in Uandinvalid portfor usb.npm test291 passing, lint clean.tcpip()/usb()round trips on each of API 30 and 36 all resolved, withservice.adb.tcp.port5555/0after each.tcpip(0)rejects with"invalid port 0", and both are back in USB mode.🤖 Generated with Claude Code