Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid flushing the stream after writing a message in case the server returns a single response #9273

Merged
merged 1 commit into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/java/io/grpc/internal/ServerCallImpl.java
Expand Up @@ -169,7 +169,9 @@ private void sendMessageInternal(RespT message) {
try {
InputStream resp = method.streamResponse(message);
stream.writeMessage(resp);
stream.flush();
if (!getMethodDescriptor().getType().serverSendsOneMessage()) {
stream.flush();
}
} catch (RuntimeException e) {
close(Status.fromThrowable(e), new Metadata());
} catch (Error e) {
Expand Down
Expand Up @@ -189,7 +189,6 @@ public void sendMessage() {
call.sendMessage(1234L);

verify(stream).writeMessage(isA(InputStream.class));
verify(stream).flush();
}

@Test
Expand Down
Expand Up @@ -347,10 +347,10 @@ public void statsRecorded() throws Exception {
fakeClock.forwardTime(2, SECONDS);
serverCall.sendHeaders(new Metadata());
serverCall.sendMessage(3);
serverCall.close(Status.OK, new Metadata());
call.request(1);
assertInboundMessageRecorded();
assertInboundWireSizeRecorded(1);
serverCall.close(Status.OK, new Metadata());
assertRpcStatusRecorded(Status.Code.OK, 2000, 2);
assertRetryStatsRecorded(1, 0, 10_000);
}
Expand Down