Repository navigation
Send END_STREAM with the unary gRPC request message - #3818
Conversation
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
left a comment
There was a problem hiding this comment.
Please sign the Square CLA before we can merge this: https://docs.google.com/forms/d/e/1FAIpQLSeRVQ35-gq2vdSxD1kdh7CJwRdjmUA0EZ9gRXaWYoUeKPZEQQ/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
| * | ||
| * This is false by default. | ||
| */ | ||
| fun endStreamOnLastUnaryMessage(enabled: Boolean) = apply { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Fixes #3815