From c705379adb0a0facef32fb8f95cde892207cadbb Mon Sep 17 00:00:00 2001 From: norman Date: Fri, 4 May 2012 10:27:58 +0200 Subject: [PATCH] Notify ChannelFuture's of queued writes if the SslHandler gets remove d from the ChannelPipeline. See #306 --- .../java/io/netty/handler/ssl/SslHandler.java | 34 ++++++++++++++++++- 1 file changed, 33 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 1bce7ff01d..c5046979e5 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -1211,9 +1211,41 @@ public class SslHandler extends FrameDecoder // Unused } + /** + * Fail all pending writes which we were not able to flush out + */ @Override public void afterRemove(ChannelHandlerContext ctx) throws Exception { - // Unused + + // there is no need for synchronization here as we do not receive downstream events anymore + Throwable cause = null; + for (;;) { + PendingWrite pw = pendingUnencryptedWrites.poll(); + if (pw == null) { + break; + } + if (cause == null) { + cause = new IOException("Unable to write data"); + } + pw.future.setFailure(cause); + + } + + for (;;) { + MessageEvent ev = pendingEncryptedWrites.poll(); + if (ev == null) { + break; + } + if (cause == null) { + cause = new IOException("Unable to write data"); + } + ev.getFuture().setFailure(cause); + + } + + if (cause != null) { + fireExceptionCaught(ctx, cause); + } }