Repository navigation
fix(tcpusb): ack A_WRTE only after the device side took the bytes - #600
Merged
koral-- merged 1 commit intoNov 26, 2026
Merged
Conversation
Without delayed_ack, the bridge wrote the client's data to the device transport and sent A_OKAY right away. A_OKAY is what lets the client send its next A_WRTE, so a client faster than the device could keep sending and everything the device had not taken yet piled up in the bridge. The delayed_ack path already waits for the write callback. Use the same path for both: SendWindow.ack() returns no payload without delayed_ack, so the plain A_OKAY is unchanged. Signed-off-by: dlstjd0237 <[email protected]>
dlstjd0237
force-pushed
the
fix/tcpusb-write-backpressure
branch
from
November 26, 2026 08:02
f92578d to
ec283ba
Compare
koral--
approved these changes
Nov 26, 2026
koral--
added a commit
that referenced
this pull request
Nov 26, 2026
…, early writes) (#601) * fix(tcpusb): ack reverse A_WRTE only after the local reader took the 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]> * fix(tcpusb): close a reverse stream written to before it was open 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]> * fix(tcpusb): close a stream whose client writes past its window 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]> --------- 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.
Bug
Without
delayed_ack,Service._handleWritePacketwrites the client's data to the device transport and sendsA_OKAYright away:A_OKAYis what lets the client send its nextA_WRTE. So the client is never held back: when it sends faster than the device takes the data, everything the device has not taken yet piles up in the bridge process, and the memory is not handed back to the OS afterwards.The
delayed_ackpath right below already waits for the write callback ("so a slow device pushes back"), and #575 fixed the same kind of problem forsync.push(). This is the same thing on the TcpUsb bridge, for clients withoutdelayed_ack(older adb clients).How it shows up
stf runs one bridge per device for "Remote debug" (
adb connect). Pushing a 2 GB file through it from a client on a fast network to a device on USB:The file arrived intact in both cases. With large repeated uploads (a load test pushing several GB), single bridge processes reached ~4 GB, and several at once took a host into the OOM killer.
I measured this on the 3.3.x bridge, whose non-
delayed_ackwrite path is the same code as onmaster. The unit tests below exercisemaster.Fix
Use the
delayed_ackpath for both cases.SendWindow.ack()returns no payload withoutdelayed_ack, so theA_OKAYthe client gets is unchanged; it is only sent once the device side has taken the bytes. A failed write ends the stream, as on thedelayed_ackpath.Tests
New
test/adb/tcpusb/service.mts:A_OKAYbefore the transport's write callback, then one plainA_OKAYwith the right ids.Both fail without the fix.
npm test: 399 passing.npm run lint: clean.