Skip to content

Commit

Permalink
Remove confusing closeSocket method.
Browse files Browse the repository at this point in the history
Remove nested exception catch, doesn't seem very useful.
58103: Add some sync to avoid double close.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1691974 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Jul 20, 2015
1 parent 0db2e46 commit e07563c
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions java/org/apache/tomcat/util/net/Nio2Endpoint.java
Expand Up @@ -430,26 +430,30 @@ public void closeSocket(SocketWrapperBase<Nio2Channel> socket) {
}
try {
handler.release(socket);
try {
if (socket.getSocket() != null) {
socket.getSocket().close(true);
}
} catch (Exception e){
if (log.isDebugEnabled()) {
log.debug(sm.getString(
"endpoint.debug.socketCloseFail"), e);
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
if (log.isDebugEnabled()) log.error("",e);
}
try {
if (socket.getSocket() != null) {
synchronized (socket.getSocket()) {
if (socket.getSocket() != null && socket.getSocket().isOpen()) {
countDownConnection();
socket.getSocket().close(true);
}
}
}
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
if (log.isDebugEnabled()) log.error("",e);
}
try {
Nio2SocketWrapper nio2Socket = (Nio2SocketWrapper) socket;
try {
if (nio2Socket.getSendfileData() != null
&& nio2Socket.getSendfileData().fchannel != null
&& nio2Socket.getSendfileData().fchannel.isOpen()) {
nio2Socket.getSendfileData().fchannel.close();
}
} catch (Exception ignore) {
if (nio2Socket.getSendfileData() != null
&& nio2Socket.getSendfileData().fchannel != null
&& nio2Socket.getSendfileData().fchannel.isOpen()) {
nio2Socket.getSendfileData().fchannel.close();
}
countDownConnection();
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
if (log.isDebugEnabled()) log.error("",e);
Expand Down Expand Up @@ -523,12 +527,24 @@ public void run() {
// Hand this socket off to an appropriate processor
if (!setSocketOptions(socket)) {
countDownConnection();
closeSocket(socket);
}
try {
socket.close();
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
log.debug("", ioe);
}
}
}
} else {
countDownConnection();
// Close socket right away
closeSocket(socket);
try {
socket.close();
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
log.debug("", ioe);
}
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
Expand All @@ -541,17 +557,6 @@ public void run() {
}


private void closeSocket(AsynchronousSocketChannel socket) {
try {
socket.close();
} catch (IOException ioe) {
if (log.isDebugEnabled()) {
log.debug("", ioe);
}
}
}


public static class Nio2SocketWrapper extends SocketWrapperBase<Nio2Channel> {

private static final ThreadLocal<AtomicInteger> nestedWriteCompletionCount =
Expand Down

0 comments on commit e07563c

Please sign in to comment.