diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java index ef87c6de15..ebbefadc07 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodec.java @@ -245,10 +245,20 @@ public class Http2FrameCodec extends Http2ConnectionHandler { * HTTP/2 on stream 1 (the stream specifically reserved for cleartext HTTP upgrade). */ @Override - public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + public final void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception { if (evt == Http2ConnectionPrefaceAndSettingsFrameWrittenEvent.INSTANCE) { // The user event implies that we are on the client. tryExpandConnectionFlowControlWindow(connection()); + + // We schedule this on the EventExecutor to allow to have any extra handlers added to the pipeline + // before we pass the event to the next handler. This is needed as the event may be called from within + // handlerAdded(...) which will be run before other handlers will be added to the pipeline. + ctx.executor().execute(new Runnable() { + @Override + public void run() { + ctx.fireUserEventTriggered(evt); + } + }); } else if (evt instanceof UpgradeEvent) { UpgradeEvent upgrade = (UpgradeEvent) evt; try { @@ -268,9 +278,9 @@ public class Http2FrameCodec extends Http2ConnectionHandler { } finally { upgrade.release(); } - return; + } else { + ctx.fireUserEventTriggered(evt); } - super.userEventTriggered(ctx, evt); } /**