From 8a095d0244da237f6eb76c4c24be49a1833b3988 Mon Sep 17 00:00:00 2001 From: Bryce Anderson Date: Thu, 25 Jan 2018 14:26:45 -0700 Subject: [PATCH] Http2MultiplexCodec should propagate unhandled Http2Frames down the pipeline Motivation: Http2MultiplexCodec swallows Http2PingFrames without releasing the payload, resulting in a memory leak. Modification: Send unhandled frames down the pipeline for consumption/disposal by another InboundChannelHandler. Result: Fixes #7607. --- .../handler/codec/http2/Http2MultiplexCodec.java | 3 +++ .../handler/codec/http2/Http2MultiplexCodecTest.java | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodec.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodec.java index ae98bfea08..aeeec3feb6 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodec.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodec.java @@ -227,6 +227,9 @@ public class Http2MultiplexCodec extends Http2FrameCodec { if (settings.initialWindowSize() != null) { initialOutboundStreamWindow = settings.initialWindowSize(); } + } else { + // Send any other frames down the pipeline + ctx.fireChannelRead(frame); } } diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexCodecTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexCodecTest.java index ecdcdcf7c8..bec5cd964e 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexCodecTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexCodecTest.java @@ -170,6 +170,17 @@ public class Http2MultiplexCodecTest { verifyFramesMultiplexedToCorrectChannel(inboundStream, inboundHandler, 2); } + @Test + public void unhandledHttp2FramesShouldBePropagated() { + ByteBuf content = UnpooledByteBufAllocator.DEFAULT.buffer(8).writeLong(0); + Http2PingFrame decodedFrame = new DefaultHttp2PingFrame(content); + + codec.onHttp2Frame(decodedFrame); + Http2PingFrame receivedPing = parentChannel.readInbound(); + assertSame(receivedPing, decodedFrame); + assertTrue(receivedPing.release()); + } + @Test public void channelReadShouldRespectAutoRead() { LastInboundHandler inboundHandler = streamActiveAndWriteHeaders(inboundStream);