diff --git a/netty/src/main/java/io/grpc/netty/NettyServerHandler.java b/netty/src/main/java/io/grpc/netty/NettyServerHandler.java index 89cf1555123..80322a861b4 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerHandler.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerHandler.java @@ -791,11 +791,13 @@ private void sendGrpcFrame(ChannelHandlerContext ctx, SendGrpcFrameCommand cmd, PerfMark.startTask("NettyServerHandler.sendGrpcFrame", cmd.stream().tag()); PerfMark.linkIn(cmd.getLink()); try { - if (cmd.endStream()) { - closeStreamWhenDone(promise, cmd.stream().id()); + int streamId = cmd.stream().id(); + Http2Stream stream = connection().stream(streamId); + if (stream != null && cmd.endStream()) { + closeStreamWhenDone(promise, streamId); } // Call the base class to write the HTTP/2 DATA frame. - encoder().writeData(ctx, cmd.stream().id(), cmd.content(), 0, cmd.endStream(), promise); + encoder().writeData(ctx, streamId, cmd.content(), 0, cmd.endStream(), promise); } finally { PerfMark.stopTask("NettyServerHandler.sendGrpcFrame", cmd.stream().tag()); }