Repository navigation
fix(tcpusb): flow control on client writes (reverse acks, write limit, early writes) - #601
Merged
Merged
Conversation
…bytes Follow-up to #600. ReverseStream still acked an A_WRTE right away when delayed_ack is off, so a client sending into an `adb reverse` stream faster than the device read it piled the data up in the bridge process. Use the write-callback path for both cases, as Service now does. Also cover Service's delayed_ack write path, which #600's tests left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client may only write once it has accepted our A_OPEN with an A_OKAY; before that we have no remote id to ack to, so close the stream instead of passing the data to the local reader. Tests: a reverse write that completes after the client's A_CLSE sends no A_OKAY, and Service's window is picked from a real A_OPEN (delayed acks only when the client has them and gives credit). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Service and ReverseStream passed every A_WRTE on to the device side, however many were still waiting there. A client that did not wait for our A_OKAY, or sent past its delayed_ack credit, to a device side that reads slowly made the bridge buffer without limit. Count what each stream has taken but not yet written: one A_WRTE without delayed_ack, the credit we gave plus one payload with it (adb sends while any credit is left). A client past that breaks the protocol, so close that stream. Pausing the client socket instead would also stop every other stream on the connection. Co-Authored-By: Claude Opus 5.5 <[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.
Follow-up to #600. Three commits, one per fix.
1. Ack reverse
A_WRTEonly after the local reader took the bytes#600 fixed
Service, butReverseStream._writestill acked right away for clients withoutdelayed_ack. On anadb reversestream, a client sending faster than the device app reads piled the data up in the bridge. Same fix as #600:A_OKAYgoes out from the write callback, and a failed write ends the stream.2. Close a reverse stream written to before it was open
ReverseStream.handle()passed anA_WRTEon even before the client accepted ourA_OPEN, and acked it to remote id 0. The stream is registered as soon as it's created (socket.ts), so this was reachable. Such a write now closes the stream.3. Close a stream whose client writes past its window
Neither
ServicenorReverseStreamlimited what a client could have waiting for the device side. A client that ignored ourA_OKAY, or sent past itsdelayed_ackcredit, could make the bridge buffer without limit. In stf that is one bridge per device, all on one host.The new
ReceiveWindowcounts, per stream, what was taken but not yet written:delayed_ack: oneA_WRTE, since the client must wait for eachA_OKAY;INITIAL_WINDOW, topped up by each ack) plus one payload, because adb sends while any credit is left, so its last packet can go past it.A client that goes past that breaks the protocol, so that stream is closed. Pausing the client socket instead would also stop every other stream on the connection.
Tests
npm test: 420 passing.npm run lint: clean.reversestream.mts(both modes):A_OKAYheld until the write callback; a failed write sendsA_CLSE; noA_OKAYfor a write completing after the client'sA_CLSE; a write before the stream is open closes it; the window limit.service.mts: thedelayed_ackwrite path; the window picked from a realA_OPEN(delayed only when the client has it and gives credit); the window limit, including after anA_OPENthat turned delayed acks off.I checked each new test by breaking the code it covers; each break makes it fail.
Checked on an emulator
Bridge over an emulator, connected with adb 37.0.3. I ran this once as is (no
delayed_ack) and once withADB_BURST_MODE=1(the bridge negotiateddelayed_ack). In both:adb pushof 256 MiB through the bridge matched its md5,adb shellworked, and 128 MiB sent throughadb reverseto a slow device-side reader arrived in full. No stream was closed by the new limit.Commit 1 on its own, without
delayed_ack, same reverse transfer:Risk
A client that pipelines writes without waiting for acks, which it shouldn't, now gets that stream closed instead of having the bridge buffer for it. adb's own client waits for acks, as verified above in both modes.
🤖 Generated with Claude Code