diff --git a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java index 0fcc2bd054..34cac60dd0 100644 --- a/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java +++ b/src/main/java/org/jboss/netty/handler/ssl/SslHandler.java @@ -1222,8 +1222,40 @@ public class SslHandler extends FrameDecoder // Unused } + /** + * Fail all pending writes which we were not able to flush out + */ 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); + } }