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 e03abd2165..83d9eb5ce7 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 @@ -305,6 +305,12 @@ public final class Http2MultiplexCodec extends ChannelDuplexHandler { } channel.pipeline().addLast(handler); + // We need to copy parent's channel options into a child's options to make + // sure they share same allocator, same receive buffer allocator, etc. + // + // See https://github.com/netty/netty/issues/6551 + channel.config().setOptions(parentChannel.config().getOptions()); + initOpts(channel, options); initAttrs(channel, attrs); 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 95e57a5e24..c17c1970da 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 @@ -39,6 +39,7 @@ import org.junit.Before; import org.junit.Test; import static io.netty.util.ReferenceCountUtil.release; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -343,6 +344,28 @@ public class Http2MultiplexCodecTest { assertEquals("bar", channel.attr(key).get()); } + @Test + public void childChannelShouldShareParentsChannelOptions() { + EmbeddedChannel parent = new EmbeddedChannel(); + parent.config().setAutoRead(false); + parent.config().setWriteSpinCount(42); + + Http2StreamChannelBootstrap b = new Http2StreamChannelBootstrap(); + parent.pipeline().addLast(new Http2MultiplexCodec(true, b)); + + Channel child = b + .parentChannel(parent) + .handler(new TestChannelInitializer()) + .connect() + .channel(); + + assertFalse(child.config().isAutoRead()); + assertEquals(child.config().getWriteSpinCount(), 42); + + child.close(); + assertTrue(!parent.finish()); + } + @Test public void outboundStreamShouldWriteGoAwayWithoutReset() { childChannelInitializer.handler = new ChannelInboundHandlerAdapter() {