Skip to content

Commit

Permalink
Improve tracking of connection closure.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1833906 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jun 20, 2018
1 parent 332877b commit ed4b9d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions java/org/apache/tomcat/util/net/Nio2Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ protected AtomicInteger initialValue() {
private final Semaphore writePending = new Semaphore(1);
private boolean writeInterest = false; // Guarded by writeCompletionHandler
private boolean writeNotify = false;
private boolean closed = false;
private volatile boolean closed = false;

private CompletionHandler<Integer, SocketWrapperBase<Nio2Channel>> awaitBytesHandler
= new CompletionHandler<Integer, SocketWrapperBase<Nio2Channel>>() {
Expand Down Expand Up @@ -842,7 +842,7 @@ public void close() throws IOException {

@Override
public boolean isClosed() {
return !getSocket().isOpen();
return closed || !getSocket().isOpen();
}


Expand Down
5 changes: 4 additions & 1 deletion java/org/apache/tomcat/util/net/NioEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public void run() {
// since it won't have been counted down when the socket
// closed.
socket.socketWrapper.getEndpoint().countDownConnection();
((NioSocketWrapper) socket.socketWrapper).closed = true;
} else {
final NioSocketWrapper socketWrapper = (NioSocketWrapper) key.attachment();
if (socketWrapper != null) {
Expand Down Expand Up @@ -682,6 +683,7 @@ public NioSocketWrapper cancelledKey(SelectionKey key) {
}
if (ka != null) {
countDownConnection();
ka.closed = true;
}
} catch (Throwable e) {
ExceptionUtils.handleThrowable(e);
Expand Down Expand Up @@ -997,6 +999,7 @@ public static class NioSocketWrapper extends SocketWrapperBase<NioChannel> {
private volatile SendfileData sendfileData = null;
private volatile long lastRead = System.currentTimeMillis();
private volatile long lastWrite = lastRead;
private volatile boolean closed = false;

public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) {
super(channel, endpoint);
Expand Down Expand Up @@ -1138,7 +1141,7 @@ public void close() throws IOException {

@Override
public boolean isClosed() {
return !getSocket().isOpen();
return closed || !getSocket().isOpen();
}


Expand Down

0 comments on commit ed4b9d7

Please sign in to comment.