From 4faad27078ddc63825fbe0f04ba3e4a0ec6dff16 Mon Sep 17 00:00:00 2001 From: Jihun Cho Date: Fri, 2 Aug 2019 16:25:08 -0700 Subject: [PATCH] netty: record ByteBuf access in Netty{Client,Server}Stream before calling MessageDeframer (#6027) --- netty/src/main/java/io/grpc/netty/NettyClientStream.java | 3 ++- netty/src/main/java/io/grpc/netty/NettyServerStream.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/netty/src/main/java/io/grpc/netty/NettyClientStream.java b/netty/src/main/java/io/grpc/netty/NettyClientStream.java index c652cd65872..c3952b43195 100644 --- a/netty/src/main/java/io/grpc/netty/NettyClientStream.java +++ b/netty/src/main/java/io/grpc/netty/NettyClientStream.java @@ -174,7 +174,8 @@ public void operationComplete(ChannelFuture future) throws Exception { private void writeFrameInternal( WritableBuffer frame, boolean endOfStream, boolean flush, final int numMessages) { Preconditions.checkArgument(numMessages >= 0); - ByteBuf bytebuf = frame == null ? EMPTY_BUFFER : ((NettyWritableBuffer) frame).bytebuf(); + ByteBuf bytebuf = + frame == null ? EMPTY_BUFFER : ((NettyWritableBuffer) frame).bytebuf().touch(); final int numBytes = bytebuf.readableBytes(); if (numBytes > 0) { // Add the bytes to outbound flow control. diff --git a/netty/src/main/java/io/grpc/netty/NettyServerStream.java b/netty/src/main/java/io/grpc/netty/NettyServerStream.java index 1864c358e26..6391fa53d9e 100644 --- a/netty/src/main/java/io/grpc/netty/NettyServerStream.java +++ b/netty/src/main/java/io/grpc/netty/NettyServerStream.java @@ -150,7 +150,7 @@ private void writeFrameInternal(WritableBuffer frame, boolean flush, final int n writeQueue.scheduleFlush(); return; } - ByteBuf bytebuf = ((NettyWritableBuffer) frame).bytebuf(); + ByteBuf bytebuf = ((NettyWritableBuffer) frame).bytebuf().touch(); final int numBytes = bytebuf.readableBytes(); // Add the bytes to outbound flow control. onSendingBytes(numBytes);