From 24bf36721d79921eacd02d331b8d06faa90d4258 Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 2 Oct 2015 10:41:40 -0700 Subject: [PATCH] DefaultHttp2ConnectionDecoder write ping buffer Motivation: DefaultHttp2ConnectionDecoder writes a ACK when receiving a ping frame and sends the same data buffer it received. The data buffer is also passed to the listener, but the indexes are shared between the send and the listener. We should ensure the indexes are independent for these two operations. Modifications: - Call slice on the buffer that is being sent Result: Listener now has access to a buffer that will not appear to be already consumed. --- .../handler/codec/http2/DefaultHttp2ConnectionDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java index 94439c10e8..882beb1200 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoder.java @@ -442,7 +442,7 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder { public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception { // Send an ack back to the remote client. // Need to retain the buffer here since it will be released after the write completes. - encoder.writePing(ctx, true, data.retain(), ctx.newPromise()); + encoder.writePing(ctx, true, data.slice().retain(), ctx.newPromise()); listener.onPingRead(ctx, data); }