HTTPCLIENT-1923: fixed incorrect connection close on shutdown + fixed corresponding test

This commit is contained in:
Aleksei Arsenev 2018-05-11 13:14:47 +03:00 committed by Oleg Kalnichevski
parent 460b60607d
commit eb27f9ee29
2 changed files with 8 additions and 22 deletions

View File

@ -157,7 +157,9 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
@Override
public void close() {
shutdown();
if (this.isShutdown.compareAndSet(false, true)) {
closeConnection();
}
}
HttpRoute getRoute() {
@ -206,7 +208,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
};
}
private void closeConnection() {
private synchronized void closeConnection() {
if (this.conn != null) {
this.log.debug("Closing connection");
try {
@ -220,20 +222,6 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
}
private void shutdownConnection() {
if (this.conn != null) {
this.log.debug("Shutting down connection");
try {
this.conn.shutdown();
} catch (final IOException iox) {
if (this.log.isDebugEnabled()) {
this.log.debug("I/O exception shutting down connection", iox);
}
}
this.conn = null;
}
}
private void checkExpiry() {
if (this.conn != null && System.currentTimeMillis() >= this.expiry) {
if (this.log.isDebugEnabled()) {
@ -373,10 +361,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
@Override
public synchronized void shutdown() {
if (this.isShutdown.compareAndSet(false, true)) {
shutdownConnection();
}
public void shutdown() {
close();
}
}

View File

@ -278,7 +278,7 @@ public class TestBasicHttpClientConnectionManager {
mgr.shutdown();
Mockito.verify(conn, Mockito.times(1)).shutdown();
Mockito.verify(conn, Mockito.times(1)).close();
try {
final ConnectionRequest connRequest2 = mgr.requestConnection(route, null);
@ -292,7 +292,7 @@ public class TestBasicHttpClientConnectionManager {
mgr.closeIdleConnections(0L, TimeUnit.MILLISECONDS);
mgr.shutdown();
Mockito.verify(conn, Mockito.times(1)).shutdown();
Mockito.verify(conn, Mockito.times(1)).close();
}
@Test