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 ec580a4ae3..cddeab61d6 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -930,6 +930,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH } boolean wrapLater = false; + boolean notifyClosure = false; ByteBuf decodeOut = allocate(ctx, initialOutAppBufCapacity); try { for (;;) { @@ -941,8 +942,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH if (status == Status.CLOSED) { // notify about the CLOSED state of the SSLEngine. See #137 - sslCloseFuture.trySuccess(ctx.channel()); - break; + notifyClosure = true; } switch (handshakeStatus) { @@ -984,6 +984,10 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH if (wrapLater) { wrap(ctx, true); } + + if (notifyClosure) { + sslCloseFuture.trySuccess(ctx.channel()); + } } catch (SSLException e) { setHandshakeFailure(e); throw e; diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java index 6e6d16edc6..04cc2083f8 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/SocketSslEchoTest.java @@ -315,8 +315,7 @@ public class SocketSslEchoTest extends AbstractSocketTest { } @Override - public void channelActive(ChannelHandlerContext ctx) - throws Exception { + public void channelActive(ChannelHandlerContext ctx) throws Exception { channel = ctx.channel(); } @@ -345,7 +344,10 @@ public class SocketSslEchoTest extends AbstractSocketTest { counter > data.length / 2 && renegoFuture == null) { SslHandler sslHandler = ctx.pipeline().get(SslHandler.class); + Future hf = sslHandler.handshakeFuture(); + assertThat(hf.isDone(), is(true)); + renegoFuture = sslHandler.renegotiate(); assertThat(renegoFuture, is(not(sameInstance(hf)))); assertThat(renegoFuture, is(sameInstance(sslHandler.handshakeFuture()))); @@ -366,13 +368,13 @@ public class SocketSslEchoTest extends AbstractSocketTest { @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof SslHandshakeCompletionEvent) { + assertSame(SslHandshakeCompletionEvent.SUCCESS, evt); negoCounter ++; } } @Override - public void exceptionCaught(ChannelHandlerContext ctx, - Throwable cause) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { if (logger.isWarnEnabled()) { logger.warn( "Unexpected exception from the " +