From 51629245d041718ca7d704a61474c7a365577cbb Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sun, 11 Sep 2016 08:52:25 +0200 Subject: [PATCH] Call debugData.retain() before we forward the frame to the pipeline Motivation: We need to call debugData.retain() before we forward the frame to the pipeline as ByteToMessageDecoder will call release() on the buffer. Modifications: Correctly retain debugData and fix the unit test to test for it. Result: No more IllegalReferenceCountException when using the Http2FrameCodec. --- .../io/netty/handler/codec/http2/Http2FrameCodec.java | 2 +- .../netty/handler/codec/http2/Http2FrameCodecTest.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java index b9cd604063..d4e81d942a 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java @@ -216,7 +216,7 @@ public class Http2FrameCodec extends ChannelDuplexHandler { @Override public void onGoAwayReceived(final int lastStreamId, long errorCode, ByteBuf debugData) { - ctx.fireChannelRead(new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, debugData)); + ctx.fireChannelRead(new DefaultHttp2GoAwayFrame(lastStreamId, errorCode, debugData.retain())); } } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java index c8fabd3004..dd95e02344 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2FrameCodecTest.java @@ -66,10 +66,10 @@ public class Http2FrameCodecTest { private ChannelHandlerContext http2HandlerCtx; private LastInboundHandler inboundHandler; - private Http2Headers request = new DefaultHttp2Headers() + private final Http2Headers request = new DefaultHttp2Headers() .method(HttpMethod.GET.asciiName()).scheme(HttpScheme.HTTPS.name()) .authority(new AsciiString("example.org")).path(new AsciiString("/foo")); - private Http2Headers response = new DefaultHttp2Headers() + private final Http2Headers response = new DefaultHttp2Headers() .status(HttpResponseStatus.OK.codeAsText()); @Before @@ -242,8 +242,10 @@ public class Http2FrameCodecTest { @Test public void receiveGoaway() throws Exception { - frameListener.onGoAwayRead(http2HandlerCtx, 2, Http2Error.NO_ERROR.code(), bb("foo")); - + ByteBuf debugData = bb("foo"); + frameListener.onGoAwayRead(http2HandlerCtx, 2, Http2Error.NO_ERROR.code(), debugData); + // Release debugData to emulate ByteToMessageDecoder + debugData.release(); Http2GoAwayFrame expectedFrame = new DefaultHttp2GoAwayFrame(2, Http2Error.NO_ERROR.code(), bb("foo")); Http2GoAwayFrame actualFrame = inboundHandler.readInbound();