SslHandler now swallows ClosedChannelException for all written non-app data

This commit is contained in:
Trustin Lee 2009-04-15 22:50:54 +00:00
parent 7d8d924f6b
commit 7d3fde9b14

View File

@ -139,7 +139,8 @@ public class SslHandler extends FrameDecoder {
private final AtomicBoolean sentFirstMessage = new AtomicBoolean(); private final AtomicBoolean sentFirstMessage = new AtomicBoolean();
private final AtomicBoolean sentCloseNotify = new AtomicBoolean(); private final AtomicBoolean sentCloseNotify = new AtomicBoolean();
final AtomicBoolean ignoreClosedChannelException = new AtomicBoolean(); int ignoreClosedChannelException;
final Object ignoreClosedChannelExceptionLock = new Object();
private final Queue<PendingWrite> pendingUnencryptedWrites = new LinkedList<PendingWrite>(); private final Queue<PendingWrite> pendingUnencryptedWrites = new LinkedList<PendingWrite>();
private final Queue<MessageEvent> pendingEncryptedWrites = new LinkedList<MessageEvent>(); private final Queue<MessageEvent> pendingEncryptedWrites = new LinkedList<MessageEvent>();
@ -386,11 +387,14 @@ public class SslHandler extends FrameDecoder {
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if (cause instanceof IOException) { if (cause instanceof IOException) {
if (cause instanceof ClosedChannelException) { if (cause instanceof ClosedChannelException) {
if (ignoreClosedChannelException.compareAndSet(true, false)) { synchronized (ignoreClosedChannelExceptionLock) {
logger.debug( if (ignoreClosedChannelException > 0) {
"Swallowing an exception raised while writing " + ignoreClosedChannelException --;
"'closure_notify'", cause); logger.debug(
return; "Swallowing an exception raised while " +
"writing non-app data", cause);
return;
}
} }
} else if (engine.isOutboundDone()) { } else if (engine.isOutboundDone()) {
String message = String.valueOf(cause.getMessage()).toLowerCase(); String message = String.valueOf(cause.getMessage()).toLowerCase();
@ -659,6 +663,17 @@ public class SslHandler extends FrameDecoder {
if (future == null) { if (future == null) {
future = succeededFuture(channel); future = succeededFuture(channel);
} else {
future.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future)
throws Exception {
if (future.getCause() instanceof ClosedChannelException) {
synchronized (ignoreClosedChannelExceptionLock) {
ignoreClosedChannelException ++;
}
}
}
});
} }
return future; return future;
} }
@ -793,9 +808,7 @@ public class SslHandler extends FrameDecoder {
ChannelFuture closeNotifyFuture = wrapNonAppData(context, e.getChannel()); ChannelFuture closeNotifyFuture = wrapNonAppData(context, e.getChannel());
closeNotifyFuture.addListener(new ChannelFutureListener() { closeNotifyFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture closeNotifyFuture) throws Exception { public void operationComplete(ChannelFuture closeNotifyFuture) throws Exception {
if (closeNotifyFuture.getCause() instanceof ClosedChannelException) { if (!(closeNotifyFuture.getCause() instanceof ClosedChannelException)) {
ignoreClosedChannelException.set(true);
} else {
Channels.close(context, e.getFuture()); Channels.close(context, e.getFuture());
} }
} }