From a7629dd21a93f8c7febd1631ac4e7ccc85422947 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 30 Jan 2015 07:28:04 +0100 Subject: [PATCH] [#3364] Not use VoidChannelPromise in SslHandler to guard against IllegalStateException Motivation: SslHandler adds a pending write with an empty buffer and a VoidChannelPromise when a user flush and not pending writes are currently stored. This may produce an IllegalStateException later if the user try to add a ChannelFutureListener to the promise in the next ChannelOutboundHandler. Modifications: Replace ctx.voidPromise() with ctx.newPromise() Result: No more IllegalStateException possible --- handler/src/main/java/io/netty/handler/ssl/SslHandler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 e1b6d708ed..dde3bc5dc4 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -414,7 +414,11 @@ public class SslHandler extends ByteToMessageDecoder { return; } if (pendingUnencryptedWrites.isEmpty()) { - pendingUnencryptedWrites.add(Unpooled.EMPTY_BUFFER, ctx.voidPromise()); + // It's important to NOT use a voidPromise here as the user + // may want to add a ChannelFutureListener to the ChannelPromise later. + // + // See https://github.com/netty/netty/issues/3364 + pendingUnencryptedWrites.add(Unpooled.EMPTY_BUFFER, ctx.newPromise()); } if (!handshakePromise.isDone()) { flushedBeforeHandshake = true;