diff --git a/handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java b/handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java index 7f0b4c17b8..266bfd8de3 100644 --- a/handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java @@ -117,6 +117,9 @@ public abstract class ApplicationProtocolNegotiationHandler implements ChannelHa @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof SslHandshakeCompletionEvent) { + // Let's first fire the event before we try to modify the pipeline. + ctx.fireUserEventTriggered(evt); + SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt; try { if (handshakeEvent.isSuccess()) { @@ -137,7 +140,6 @@ public abstract class ApplicationProtocolNegotiationHandler implements ChannelHa } catch (Throwable cause) { exceptionCaught(ctx, cause); } finally { - ctx.fireUserEventTriggered(evt); // Handshake failures are handled in exceptionCaught(...). if (handshakeEvent.isSuccess()) { removeSelfIfPresent(ctx);