Skip to content

Commit

Permalink
INT-3098 TCP Suppress Error Log on Normal Close
Browse files Browse the repository at this point in the history
Net connections suppress error logs, NIO connections did not.
  • Loading branch information
garyrussell committed Sep 18, 2013
1 parent 7f34f8c commit 772a01b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -308,6 +310,14 @@ public String getConnectionId() {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,10 +79,11 @@ public TcpNetConnection(Socket socket, boolean server, boolean lookupHost,
*/
@Override
public void close() {
this.noReadErrorOnClose = true;
this.setNoReadErrorOnClose(true);
try {
this.socket.close();
} catch (Exception e) {}
}
catch (Exception e) {}
super.close();
}

Expand Down Expand Up @@ -217,7 +216,7 @@ protected boolean handleReadException(Exception e) {
}
}
if (doClose) {
boolean noReadErrorOnClose = this.noReadErrorOnClose;
boolean noReadErrorOnClose = this.isNoReadErrorOnClose();
this.closeConnection();
if (!(e instanceof SoftEndOfStreamException)) {
if (e instanceof SocketTimeoutException && this.isSingleUse()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@ public void setPipeTimeout(long pipeTimeout) {

@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();
}

Expand Down Expand Up @@ -211,12 +214,20 @@ public void run() {
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;
Expand Down

0 comments on commit 772a01b

Please sign in to comment.