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 124e27b8a0..824013efb4 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -1230,6 +1230,48 @@ public class SslHandler extends FrameDecoder super.channelConnected(ctx, e); } + /** + * Loop over all the pending writes and fail them. + * + * See #305 for more details. + */ + @Override + public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { + Throwable cause = null; + synchronized (pendingUnencryptedWrites) { + for (;;) { + PendingWrite pw = pendingUnencryptedWrites.poll(); + if (pw == null) { + break; + } + if (cause == null) { + cause = new ClosedChannelException(); + } + pw.future.setFailure(cause); + + } + + + for (;;) { + MessageEvent ev = pendingEncryptedWrites.poll(); + if (ev == null) { + break; + } + if (cause == null) { + cause = new ClosedChannelException(); + } + ev.getFuture().setFailure(cause); + + } + } + + if (cause != null) { + fireExceptionCaught(ctx, cause); + } + + super.channelClosed(ctx, e); + } + private final class SSLEngineInboundCloseFuture extends DefaultChannelFuture { public SSLEngineInboundCloseFuture() { super(null, true);