Skip to content

Commit

Permalink
While looking at BZ 57653 I found (and can reproduce with a debugger)…
Browse files Browse the repository at this point in the history
… an issue where sockets could end up being closed twice if they were in the poller, the connector is stopped and then closeSocket() was called.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1665653 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Mar 10, 2015
1 parent 8de4e76 commit 707ba1c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions java/org/apache/tomcat/util/net/AprEndpoint.java
Expand Up @@ -947,9 +947,7 @@ private void closeSocket(long socket) {
// countDownConnection() in that case
Poller poller = this.poller;
if (poller != null) {
if (!poller.close(socket)) {
destroySocket(socket);
}
poller.close(socket);
}
}

Expand Down Expand Up @@ -1420,9 +1418,24 @@ protected void destroy() {
} catch (InterruptedException e) {
// Ignore
}
// Close all sockets in the close queue
SocketInfo info = closeList.get();
while (info != null) {
// Make sure we aren't trying add the socket as well as close it
addList.remove(info.socket);
// Make sure the socket isn't in the poller before we close it
removeFromPoller(info.socket);
// Poller isn't running at this point so use destroySocket()
// directly
destroySocket(info.socket);
info = closeList.get();
}
closeList.clear();
// Close all sockets in the add queue
SocketInfo info = addList.get();
info = addList.get();
while (info != null) {
// Make sure the socket isn't in the poller before we close it
removeFromPoller(info.socket);
// Poller isn't running at this point so use destroySocket()
// directly
destroySocket(info.socket);
Expand Down Expand Up @@ -1516,17 +1529,10 @@ private boolean addToPoller(long socket, int events) {
}


protected boolean close(long socket) {
if (!pollerRunning) {
return false;
}
protected void close(long socket) {
synchronized (this) {
if (!pollerRunning) {
return false;
}
closeList.add(socket, 0, 0);
this.notify();
return true;
}
}

Expand Down

0 comments on commit 707ba1c

Please sign in to comment.