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 2020/05/27 14:39:43 UTC

[httpcomponents-client] branch master updated: Bug fix: classic connection managers fail to take #isConsistent() flag into account when re-using persistent connections

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 9cfdd54  Bug fix: classic connection managers fail to take #isConsistent() flag into account when re-using persistent connections
9cfdd54 is described below

commit 9cfdd54c94ab641a887e43ca1f4ae56beab5cd90
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed May 27 12:11:49 2020 +0200

    Bug fix: classic connection managers fail to take #isConsistent() flag into account when re-using persistent connections
---
 .../hc/client5/http/impl/io/BasicHttpClientConnectionManager.java   | 2 +-
 .../hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java | 6 +++++-
 .../http/impl/io/TestPoolingHttpClientConnectionManager.java        | 4 +++-
 3 files changed, 9 insertions(+), 3 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 eaa10e4..26b5f37 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
@@ -265,7 +265,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
                 this.conn.close(CloseMode.GRACEFUL);
             }
             this.updated = System.currentTimeMillis();
-            if (!this.conn.isOpen()) {
+            if (!this.conn.isOpen() && !this.conn.isConsistent()) {
                 this.conn = null;
                 this.route = null;
                 this.conn = null;
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
index 5600f93..7d29e2c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java
@@ -355,7 +355,7 @@ public class PoolingHttpClientConnectionManager
         if (conn != null && keepAlive == null) {
             conn.close(CloseMode.GRACEFUL);
         }
-        boolean reusable = conn != null && conn.isOpen();
+        boolean reusable = conn != null && conn.isOpen() && conn.isConsistent();
         try {
             if (reusable) {
                 entry.updateState(state);
@@ -371,6 +371,10 @@ public class PoolingHttpClientConnectionManager
                     log.debug(ConnPoolSupport.getId(endpoint) + ": connection " + ConnPoolSupport.getId(conn) +
                             " can be kept alive " + s);
                 }
+            } else {
+                if (this.log.isDebugEnabled()) {
+                    this.log.debug(ConnPoolSupport.getId(endpoint) + ": connection is not kept alive");
+                }
             }
         } catch (final RuntimeException ex) {
             reusable = false;
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
index 227fa00..7945dd1 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/io/TestPoolingHttpClientConnectionManager.java
@@ -107,6 +107,7 @@ public class TestPoolingHttpClientConnectionManager {
         Mockito.when(plainSocketFactory.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
 
         Mockito.when(conn.isOpen()).thenReturn(true);
+        Mockito.when(conn.isConsistent()).thenReturn(true);
         Mockito.when(future.isCancelled()).thenReturn(false);
         Mockito.when(future.get(1, TimeUnit.SECONDS)).thenReturn(entry);
         Mockito.when(pool.lease(
@@ -213,7 +214,8 @@ public class TestPoolingHttpClientConnectionManager {
                 Mockito.<Timeout>any(),
                 Mockito.<FutureCallback<PoolEntry<HttpRoute, ManagedHttpClientConnection>>>eq(null)))
                 .thenReturn(future);
-        Mockito.when(conn.isOpen()).thenReturn(Boolean.TRUE);
+        Mockito.when(conn.isOpen()).thenReturn(true);
+        Mockito.when(conn.isConsistent()).thenReturn(true);
 
         final LeaseRequest connRequest1 = mgr.lease("some-id", route, null);
         final ConnectionEndpoint endpoint1 = connRequest1.get(Timeout.ofSeconds(1));