HTTP/2 example upgrade refcnt bug

Motivation:
Http2ServerInitializer uses a SimpleChannelHandler in an attempt to ease putting an HttpObjectAggregator in the pipeline when no upgrade is attempted. However the message is double released because it is fired up the pipeline (which will be released) and also released by SimpleChannelHandler in a finally block.

Modifications:
- Retain the message if we fire it up the pipeline

Result:
HTTP/2 examples don't encounter a reference count error if no upgrade was attempted.
This commit is contained in:
Scott Mitchell 2016-09-16 09:09:21 -07:00
parent 3c62a20519
commit e3fbfe5641
2 changed files with 4 additions and 2 deletions

View File

@ -34,6 +34,7 @@ import io.netty.handler.codec.http2.Http2CodecUtil;
import io.netty.handler.codec.http2.Http2ServerUpgradeCodec;
import io.netty.handler.ssl.SslContext;
import io.netty.util.AsciiString;
import io.netty.util.ReferenceCountUtil;
/**
* Sets up the Netty pipeline for the example server. Depending on the endpoint config, sets up the
@ -101,7 +102,7 @@ public class Http2ServerInitializer extends ChannelInitializer<SocketChannel> {
ChannelHandlerContext thisCtx = pipeline.context(this);
pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
ctx.fireChannelRead(msg);
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
}
});

View File

@ -32,6 +32,7 @@ import io.netty.handler.codec.http2.Http2CodecUtil;
import io.netty.handler.codec.http2.Http2ServerUpgradeCodec;
import io.netty.handler.ssl.SslContext;
import io.netty.util.AsciiString;
import io.netty.util.ReferenceCountUtil;
/**
* Sets up the Netty pipeline for the example server. Depending on the endpoint config, sets up the
@ -99,7 +100,7 @@ public class Http2ServerInitializer extends ChannelInitializer<SocketChannel> {
ChannelHandlerContext thisCtx = pipeline.context(this);
pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
ctx.fireChannelRead(msg);
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
}
});