http2: Http2StreamChannel now shares options of its parent channel

Motivation

Http2StreamChannel ignores options of its parent channel when being created. That leads to surprising results when, for example, unpooled allocator could be silently replaced with pooled allocator (default setting).

Modification

Copy parent channel's options over to the Http2StreamChannel.

Result

Channel options are now consistent between Http2StreamChannel and its parent channel. Newly added test passes on this branch and fails on master. Fixes #6551.
This commit is contained in:
Vladimir Kostyukov 2017-03-20 13:14:34 -07:00 committed by Norman Maurer
parent bf08ed0b93
commit 7467106630
2 changed files with 29 additions and 0 deletions

View File

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

View File

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