HTTPCLIENT-2316: BasicHttpClientConnectionManager incorrectly re-uses the released connection if it has been closed out by the protocol handler

This commit is contained in:
Oleg Kalnichevski 2024-01-30 17:04:50 +01:00
parent 23da984fb5
commit fa8ca22d21
1 changed files with 14 additions and 6 deletions

View File

@ -69,6 +69,7 @@ import org.apache.hc.core5.io.CloseMode;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Asserts;
import org.apache.hc.core5.util.Deadline;
import org.apache.hc.core5.util.Identifiable;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.slf4j.Logger;
@ -591,7 +592,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
.build();
}
class InternalConnectionEndpoint extends ConnectionEndpoint {
class InternalConnectionEndpoint extends ConnectionEndpoint implements Identifiable {
private final HttpRoute route;
private final AtomicReference<ManagedHttpClientConnection> connRef;
@ -601,6 +602,11 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
this.connRef = new AtomicReference<>(conn);
}
@Override
public String getId() {
return id;
}
HttpRoute getRoute() {
return route;
}
@ -614,8 +620,10 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
}
ManagedHttpClientConnection getValidatedConnection() {
final ManagedHttpClientConnection conn = getConnection();
Asserts.check(conn.isOpen(), "Endpoint is not connected");
final ManagedHttpClientConnection conn = this.connRef.get();
if (conn == null || !conn.isOpen()) {
throw new ConnectionShutdownException();
}
return conn;
}
@ -625,13 +633,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
@Override
public boolean isConnected() {
final ManagedHttpClientConnection conn = getConnection();
final ManagedHttpClientConnection conn = this.connRef.get();
return conn != null && conn.isOpen();
}
@Override
public void close(final CloseMode closeMode) {
final ManagedHttpClientConnection conn = detach();
final ManagedHttpClientConnection conn = this.connRef.get();
if (conn != null) {
conn.close(closeMode);
}
@ -639,7 +647,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
@Override
public void close() throws IOException {
final ManagedHttpClientConnection conn = detach();
final ManagedHttpClientConnection conn = this.connRef.get();
if (conn != null) {
conn.close();
}