diff --git a/core/src/main/java/com/google/net/stubby/ChannelImpl.java b/core/src/main/java/com/google/net/stubby/ChannelImpl.java index 9b5722b63a..d6a17c2cd1 100644 --- a/core/src/main/java/com/google/net/stubby/ChannelImpl.java +++ b/core/src/main/java/com/google/net/stubby/ChannelImpl.java @@ -238,11 +238,14 @@ public final class ChannelImpl implements Channel { private class CallImpl extends Call { private final MethodDescriptor method; private final SerializingExecutor callExecutor; + private final boolean unaryRequest; private ClientStream stream; public CallImpl(MethodDescriptor method, SerializingExecutor executor) { this.method = method; this.callExecutor = executor; + this.unaryRequest = method.getType() == MethodType.UNARY + || method.getType() == MethodType.SERVER_STREAMING; } @Override @@ -308,7 +311,12 @@ public final class ChannelImpl implements Channel { cancel(); } } - stream.flush(); + // For unary requests, we don't flush since we know that halfClose should be coming soon. This + // allows us to piggy-back the END_STREAM=true on the last payload frame without opening the + // possibility of broken applications forgetting to call halfClose without noticing. + if (!unaryRequest) { + stream.flush(); + } } private class ClientStreamListenerImpl implements ClientStreamListener {