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.
This commit is contained in:
Norman Maurer 2016-09-11 08:52:25 +02:00
parent 9008e72c2b
commit 51629245d0
2 changed files with 7 additions and 5 deletions

View File

@ -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()));
}
}

View File

@ -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();