Skip to content

binder: add unit tests for Inbound. Use them to repro & fix an edge case in delivery - #13032

Merged
jdcormie merged 3 commits into
grpc:masterfrom
jdcormie:ooo-msg-before-prefix
Sep 17, 2026
Merged

jdcormie merged 3 commits into
grpc:masterfrom
jdcormie:ooo-msg-before-prefix

Conversation

@jdcormie

@jdcormie jdcormie commented Sep 5, 2026

Copy link
Copy Markdown
Member

Regression testing this bug fix required building unit tests for Inbound (it currently has none). We'll rely on these tests for other, bigger, upcoming changes like #12747 and #9010.

Will not squash please review each commit individually.

@jdcormie jdcormie changed the title binder: Inbound must tolerate the suffix arriving out of order binder: Inbound must deliver even if the suffix arrives out of order Sep 5, 2026
@jdcormie
jdcormie requested a review from dbgalur September 5, 2026 02:18
@jdcormie
jdcormie force-pushed the ooo-msg-before-prefix branch from ab3fd56 to 6dead46 Compare September 6, 2026 07:31
@jdcormie jdcormie changed the title binder: Inbound must deliver even if the suffix arrives out of order binder: add unit tests for Inbound. Use them to repro & fix an edge case in delivery Sep 8, 2026
@jdcormie
jdcormie force-pushed the ooo-msg-before-prefix branch 2 times, most recently from 5250095 to 6ecb42d Compare September 9, 2026 00:26
@jdcormie

Copy link
Copy Markdown
Member Author

@kannanjgithub, could you consider this for approval? My colleague has reviewed it for Android.

@jdcormie
jdcormie requested a review from ejona86 September 16, 2026 18:43
@jdcormie

Copy link
Copy Markdown
Member Author

Perhaps Eric will have a moment to consider this for approval during pacific business hours.

…getDelegate()

Permits fake/mock implementations in tests that aren't actually backed by an IBinder at all.

TAG=agy
CONV=a7051e19-0fc1-42a4-8b24-5c2e3373aa0c
It's hard to unit test Inbound in isolation because of its many
hard-coded concrete dependencies. However, without unit tests, we can't
safely refactor Inbound to fix this either! Introduce ClientInboundTest
and ServerInboundTest, which bootstrap a way out of this mess by
creating an Inbound indirectly via a dummy BinderTransport.

TAG=agy
CONV=a7051e19-0fc1-42a4-8b24-5c2e3373aa0c
Inbound's queuedTransactionData holds message fragments from the peer
that haven't yet been assembled and delivered to the application.
Binder transactions are sent in index order and must contain at least
one of: a prefix, part/all of a message, and a suffix. When a
transaction with message data arrives before its predecessors (according
to index), Inbound's enqueueTransactionData() reserves slots for those
predecessors in queuedTransactionData. After each predecessor
transaction trickles in, enqueueTransactionData() checks whether it
completes the message, which can then be delivered. There's an edge
case, though, where a late-arrival transaction contains just the prefix
with no message data at all. In that case, Inbound remove()s the
queuedTransactionData slot it previously reserved and carries on without
considering that this prefix-only transaction might have completed the
first message! And if that was the final transaction in the stream,
Inbound will never call lookForCompleteMessage() again, leaving the
stream stuck forever with a complete but undelivered message.
@jdcormie
jdcormie force-pushed the ooo-msg-before-prefix branch from 6ecb42d to e1b2c78 Compare September 16, 2026 23:00
@jdcormie
jdcormie merged commit 4865560 into grpc:master Sep 17, 2026
14 checks passed
@jdcormie
jdcormie deleted the ooo-msg-before-prefix branch September 17, 2026 05:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants