You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2024/01/31 10:42:02 UTC

(httpcomponents-client) branch master updated: HTTPCLIENT-2316: BasicHttpClientConnectionManager incorrectly re-uses the released connection if it has been closed out by the protocol handler

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new fa8ca22d2 HTTPCLIENT-2316: BasicHttpClientConnectionManager incorrectly re-uses the released connection if it has been closed out by the protocol handler
fa8ca22d2 is described below

commit fa8ca22d2106decdc938baef5bfbe9505c72c075
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Jan 30 17:04:50 2024 +0100

    HTTPCLIENT-2316: BasicHttpClientConnectionManager incorrectly re-uses the released connection if it has been closed out by the protocol handler
---
 .../impl/io/BasicHttpClientConnectionManager.java    | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
index da8b0f9b8..79078f86e 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java
@@ -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();
             }