Skip to content

Commit c7f69c8

Browse files
committed
core: Add missing setListener if decompressor is unknown
Previously AbstractServerStream would throw an exception which would kill the RPC with a RST_STREAM. Now the server actually responds with a clean error message and avoids spamming the logs. WARNING: Exception in onHeadersRead() java.lang.IllegalStateException at com.google.common.base.Preconditions.checkState(Preconditions.java:495) at io.grpc.internal.AbstractStream$TransportState.onStreamAllocated(AbstractStream.java:232) at io.grpc.internal.AbstractServerStream$TransportState.onStreamAllocated(AbstractServerStream.java:224) at io.grpc.netty.NettyServerHandler.onHeadersRead(NettyServerHandler.java:451) at io.grpc.netty.NettyServerHandler.access$900(NettyServerHandler.java:101) at io.grpc.netty.NettyServerHandler$FrameListener.onHeadersRead(NettyServerHandler.java:807) at io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder$FrameReadListener.onHeadersRead(DefaultHttp2ConnectionDecoder.java:373)
1 parent 9dec06c commit c7f69c8

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

core/src/main/java/io/grpc/internal/ServerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ private void streamCreatedInternal(
486486
String encoding = headers.get(MESSAGE_ENCODING_KEY);
487487
Decompressor decompressor = decompressorRegistry.lookupDecompressor(encoding);
488488
if (decompressor == null) {
489+
stream.setListener(NOOP_LISTENER);
489490
stream.close(
490491
Status.UNIMPLEMENTED.withDescription(
491492
String.format("Can't find decompressor for %s", encoding)),

core/src/test/java/io/grpc/internal/ServerImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ public void decompressorNotFound() throws Exception {
487487

488488
transportListener.streamCreated(stream, "Waiter/nonexist", requestHeaders);
489489

490+
verify(stream).setListener(isA(ServerStreamListener.class));
490491
verify(stream).streamId();
491492
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
492493
Status status = statusCaptor.getValue();

0 commit comments

Comments
 (0)