INT-3098 TCP Suppress Error Log on Normal Close
Net connections suppress error logs, NIO connections did not.
This commit is contained in:
@@ -86,6 +86,8 @@ public abstract class TcpConnectionSupport implements TcpConnection {
|
||||
|
||||
private final AtomicBoolean exceptionSent = new AtomicBoolean();
|
||||
|
||||
private volatile boolean noReadErrorOnClose;
|
||||
|
||||
public TcpConnectionSupport() {
|
||||
this.server = false;
|
||||
this.applicationEventPublisher = null;
|
||||
@@ -308,6 +310,14 @@ public abstract class TcpConnectionSupport implements TcpConnection {
|
||||
return this.connectionId;
|
||||
}
|
||||
|
||||
protected boolean isNoReadErrorOnClose() {
|
||||
return noReadErrorOnClose;
|
||||
}
|
||||
|
||||
protected void setNoReadErrorOnClose(boolean noReadErrorOnClose) {
|
||||
this.noReadErrorOnClose = noReadErrorOnClose;
|
||||
}
|
||||
|
||||
protected final void sendExceptionToListener(Exception e) {
|
||||
if (!this.exceptionSent.getAndSet(true) && this.getListener() != null) {
|
||||
Map<String, Object> headers = Collections.singletonMap(IpHeaders.CONNECTION_ID,
|
||||
|
||||
@@ -37,8 +37,6 @@ public class TcpNetConnection extends TcpConnectionSupport {
|
||||
|
||||
private final Socket socket;
|
||||
|
||||
private boolean noReadErrorOnClose;
|
||||
|
||||
private volatile long lastRead = System.currentTimeMillis();
|
||||
|
||||
private volatile long lastSend;
|
||||
@@ -81,10 +79,11 @@ public class TcpNetConnection extends TcpConnectionSupport {
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
this.noReadErrorOnClose = true;
|
||||
this.setNoReadErrorOnClose(true);
|
||||
try {
|
||||
this.socket.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
catch (Exception e) {}
|
||||
super.close();
|
||||
}
|
||||
|
||||
@@ -217,7 +216,7 @@ public class TcpNetConnection extends TcpConnectionSupport {
|
||||
}
|
||||
}
|
||||
if (doClose) {
|
||||
boolean noReadErrorOnClose = this.noReadErrorOnClose;
|
||||
boolean noReadErrorOnClose = this.isNoReadErrorOnClose();
|
||||
this.closeConnection();
|
||||
if (!(e instanceof SoftEndOfStreamException)) {
|
||||
if (e instanceof SocketTimeoutException && this.isSingleUse()) {
|
||||
|
||||
@@ -112,16 +112,19 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
this.setNoReadErrorOnClose(true);
|
||||
doClose();
|
||||
}
|
||||
|
||||
private void doClose() {
|
||||
try {
|
||||
channelInputStream.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
catch (IOException e) {}
|
||||
try {
|
||||
this.socketChannel.close();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
catch (Exception e) {}
|
||||
super.close();
|
||||
}
|
||||
|
||||
@@ -211,12 +214,20 @@ public class TcpNioConnection extends TcpConnectionSupport {
|
||||
logger.error("Read exception " +
|
||||
this.getConnectionId(), e);
|
||||
}
|
||||
else {
|
||||
else if (!this.isNoReadErrorOnClose()) {
|
||||
logger.error("Read exception " +
|
||||
this.getConnectionId() + " " +
|
||||
e.getClass().getSimpleName() +
|
||||
":" + e.getCause() + ":" + e.getMessage());
|
||||
}
|
||||
else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Read exception " +
|
||||
this.getConnectionId() + " " +
|
||||
e.getClass().getSimpleName() +
|
||||
":" + e.getCause() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
this.closeConnection();
|
||||
this.sendExceptionToListener(e);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user