Skip to content

Send END_STREAM with the unary gRPC request message - #3818

Merged
oldergod merged 2 commits into
square:masterfrom
aminmsvi:unary-endstream-on-message-frame
Nov 23, 2026
Merged

oldergod merged 2 commits into
square:masterfrom
aminmsvi:unary-endstream-on-message-frame

Conversation

@aminmsvi

@aminmsvi aminmsvi commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #3815

Unary request bodies are flushed after the single message and closed
right after, so the transport sends END_STREAM in a separate write.
Servers that run the unary handler only after the client's half-close
then start it one network round trip later. The new builder option,
off by default, skips that flush so END_STREAM rides the message's
own DATA frame. Streaming calls keep flushing after every message.

@oldergod oldergod left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
* This is false by default.
*/
fun endStreamOnLastUnaryMessage(enabled: Boolean) = apply {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option does not need to be opt-in.
The gRPC spec requires an empty END_STREAM DATA frame only "in scenarios where the Request stream needs to be closed but no data remains to be sent". END_STREAM on the message's own DATA frame is compliant.
newRequestBody closes the body right after the single write, so this flush gives nothing. grpc-java skips it for every unary call.
With a default of false, existing clients keep the extra round trip from #3815, and Wire keeps a public builder method that nobody needs.
Pass flushAfterWrite = false in newRequestBody and remove endStreamOnLastUnaryMessage from Builder, newBuilder(), WireGrpcClient, and RealGrpcCall. The default-behavior test then expects zero flushes.
This also removes a CI failure: the new public method is not in wire-grpc-client/api/wire-grpc-client.api, so apiCheck fails ./gradlew build.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. flush is now disabled for unary request bodies, and the public API now matches master. I've also signed the CLA.

Per review: the option does not need to be opt-in. END_STREAM on the
message's own DATA frame is spec-compliant, the flush before the
immediate close buys nothing, and grpc-java skips it for every unary
call. newRequestBody now always passes flushAfterWrite = false, the
public builder method is removed (also fixing apiCheck), and the test
asserts zero flushes on the default client.
@oldergod
oldergod enabled auto-merge November 23, 2026 12:30
@oldergod oldergod changed the title Add endStreamOnLastUnaryMessage option to GrpcClient Send END_STREAM with the unary gRPC request message Nov 23, 2026
@oldergod
oldergod merged commit a3f79be into square:master Nov 23, 2026
12 checks passed
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.

Unary gRPC requests have an extra RTT because of premature flushing of request body

2 participants