From c061bd17986785426552df659a30f4ada491350c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 20 Oct 2020 09:01:15 +0200 Subject: [PATCH] Ensure SniCompletionEvent is not lost after onLookupComplete(...) (#10709) Motivation: In the master branch we fail fire* operations on the ChannelHandlerContext once the handler was removed. This is by design as it is "unspecified" what the semantics could be after the handler was removed and may lead to very hard to debug problems. Because of this we need to select the right ChannelHandlerContext for firing the event. Modifications: Choose a valid ChannelHandlerContext based on the state of the context of the handler Result: No more test failures --- .../main/java/io/netty/handler/ssl/AbstractSniHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/AbstractSniHandler.java b/handler/src/main/java/io/netty/handler/ssl/AbstractSniHandler.java index 8f610e4459..871a318b11 100644 --- a/handler/src/main/java/io/netty/handler/ssl/AbstractSniHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/AbstractSniHandler.java @@ -132,7 +132,10 @@ public abstract class AbstractSniHandler extends SslClientHelloHandler { try { onLookupComplete(ctx, hostname, future); } finally { - fireSniCompletionEvent(ctx, hostname, future); + fireSniCompletionEvent( + // If this handler was removed as part of onLookupComplete(...) we should fire the + // event from the beginning of the pipeline as otherwise this will fail. + ctx.isRemoved() ? ctx.pipeline().firstContext() : ctx, hostname, future); } }