From a485ae68dce633a3f2da3ad7e31501561cb3d352 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 4 Jun 2015 21:02:55 +0200 Subject: [PATCH] Guard against race when calling SslHandler.handshakeFuture().sync() Motivation: If the handlerAdded(...) callback was not called, the checkDeadLock() of the handshakeFuture will produce an IllegalStateException. This was first reported at https://github.com/impossibl/pgjdbc-ng/issues/168 . Modifications: Pass deadlock check if ctx is null Result: No more race and so IllegalStateException. --- .../main/java/io/netty/handler/ssl/SslHandler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index 5a2e94cb88..1248db93df 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -1543,5 +1543,19 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH } return ctx.executor(); } + + @Override + protected void checkDeadLock() { + if (ctx == null) { + // If ctx is null the handlerAdded(...) callback was not called, in this case the checkDeadLock() + // method was called from another Thread then the one that is used by ctx.executor(). We need to + // guard against this as a user can see a race if handshakeFuture().sync() is called but the + // handlerAdded(..) method was not yet as it is called from the EventExecutor of the + // ChannelHandlerContext. If we not guard against this super.checkDeadLock() would cause an + // IllegalStateException when trying to call executor(). + return; + } + super.checkDeadLock(); + } } }