From e3fbfe564178470f4bf52a9cf5a9944d321ecb1c Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Fri, 16 Sep 2016 09:09:21 -0700 Subject: [PATCH] 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. --- .../helloworld/multiplex/server/Http2ServerInitializer.java | 3 ++- .../http2/helloworld/server/Http2ServerInitializer.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java index a5daacc842..df38b7d46c 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/Http2ServerInitializer.java @@ -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 { 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)); } }); diff --git a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java index 1aa725beec..64b221a508 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/server/Http2ServerInitializer.java @@ -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 { 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)); } });