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 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<MessageEvent> pendingEncryptedWrites = new LinkedList<MessageEvent>();
@ -386,12 +387,15 @@ public class SslHandler extends FrameDecoder {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
if (cause instanceof ClosedChannelException) {
if (ignoreClosedChannelException.compareAndSet(true, false)) {
synchronized (ignoreClosedChannelExceptionLock) {
if (ignoreClosedChannelException > 0) {
ignoreClosedChannelException --;
logger.debug(
"Swallowing an exception raised while writing " +
"'closure_notify'", cause);
"Swallowing an exception raised while " +
"writing non-app data", cause);
return;
}
}
} else if (engine.isOutboundDone()) {
String message = String.valueOf(cause.getMessage()).toLowerCase();
if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
@ -659,6 +663,17 @@ public class SslHandler extends FrameDecoder {
if (future == null) {
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;
}
@ -793,9 +808,7 @@ public class SslHandler extends FrameDecoder {
ChannelFuture closeNotifyFuture = wrapNonAppData(context, e.getChannel());
closeNotifyFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture closeNotifyFuture) throws Exception {
if (closeNotifyFuture.getCause() instanceof ClosedChannelException) {
ignoreClosedChannelException.set(true);
} else {
if (!(closeNotifyFuture.getCause() instanceof ClosedChannelException)) {
Channels.close(context, e.getFuture());
}
}