Fixed a problem where ClosedChannelException is raised when SslHandler sends a closure_notify
This commit is contained in:
parent
e323b221d7
commit
1262c45ab3
@ -138,6 +138,7 @@ 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();
|
||||||
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>();
|
||||||
|
|
||||||
@ -382,14 +383,22 @@ public class SslHandler extends FrameDecoder {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
Throwable cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
if (cause instanceof IOException && engine.isOutboundDone()) {
|
if (cause instanceof IOException) {
|
||||||
|
if (cause instanceof ClosedChannelException) {
|
||||||
|
if (ignoreClosedChannelException.compareAndSet(true, false)) {
|
||||||
|
logger.debug(
|
||||||
|
"Swallowing an exception raised while writing " +
|
||||||
|
"'closure_notify'", cause);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (engine.isOutboundDone()) {
|
||||||
String message = String.valueOf(cause.getMessage()).toLowerCase();
|
String message = String.valueOf(cause.getMessage()).toLowerCase();
|
||||||
if (CONNECTION_RESET.matcher(message).matches()) {
|
if (CONNECTION_RESET.matcher(message).matches()) {
|
||||||
// It is safe to ignore the 'connection reset by peer' error
|
// It is safe to ignore the 'connection reset by peer' error
|
||||||
// after sending closure_notify.
|
// after sending closure_notify.
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Ignoring a 'connection reset by peer' error",
|
"Swallowing a 'connection reset by peer' error " +
|
||||||
cause);
|
"occurred while writing 'closure_notify'", cause);
|
||||||
|
|
||||||
// Close the connection explicitly just in case the transport
|
// Close the connection explicitly just in case the transport
|
||||||
// did not close the connection automatically.
|
// did not close the connection automatically.
|
||||||
@ -397,6 +406,7 @@ public class SslHandler extends FrameDecoder {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctx.sendUpstream(e);
|
ctx.sendUpstream(e);
|
||||||
}
|
}
|
||||||
@ -781,8 +791,12 @@ 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) {
|
||||||
|
ignoreClosedChannelException.set(true);
|
||||||
|
} else {
|
||||||
Channels.close(context, e.getFuture());
|
Channels.close(context, e.getFuture());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user