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 2019/12/04 12:19:41 UTC

[httpcomponents-client] branch HTTPCLIENT-2033 created (now 3748805)

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

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


      at 3748805  HTTPCLIENT-2033: connection managers to immediately shut down all leased connection upon shutdown

This branch includes the following new commits:

     new 3748805  HTTPCLIENT-2033: connection managers to immediately shut down all leased connection upon shutdown

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[httpcomponents-client] 01/01: HTTPCLIENT-2033: connection managers to immediately shut down all leased connection upon shutdown

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 374880519c40672345f93086c73d2c995d6c2985
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Dec 4 12:55:00 2019 +0100

    HTTPCLIENT-2033: connection managers to immediately shut down all leased connection upon shutdown
---
 .../impl/conn/BasicHttpClientConnectionManager.java   | 14 +++++++++++++-
 .../impl/conn/PoolingHttpClientConnectionManager.java | 19 +++++++++++++++++++
 .../conn/TestBasicHttpClientConnectionManager.java    |  4 ++--
 3 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
index 8119102..8d3a70d 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
@@ -362,7 +362,19 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
 
     @Override
     public void shutdown() {
-        close();
+        if (this.isShutdown.compareAndSet(false, true)) {
+            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;
+            }
+        }
     }
 
 }
diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
index fe8ba37..a3b36aa 100644
--- a/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
+++ b/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
@@ -63,6 +63,7 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory;
 import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.pool.ConnFactory;
 import org.apache.http.pool.ConnPoolControl;
+import org.apache.http.pool.PoolEntry;
 import org.apache.http.pool.PoolEntryCallback;
 import org.apache.http.pool.PoolStats;
 import org.apache.http.protocol.HttpContext;
@@ -265,6 +266,7 @@ public class PoolingHttpClientConnectionManager
         if (this.log.isDebugEnabled()) {
             this.log.debug("Connection request: " + format(route, state) + formatStats(route));
         }
+        Asserts.check(!this.isShutDown.get(), "Connection pool shut down");
         final Future<CPoolEntry> future = this.pool.lease(route, state, null);
         return new ConnectionRequest() {
 
@@ -408,6 +410,23 @@ public class PoolingHttpClientConnectionManager
         if (this.isShutDown.compareAndSet(false, true)) {
             this.log.debug("Connection manager is shutting down");
             try {
+                this.pool.enumLeased(new PoolEntryCallback<HttpRoute, ManagedHttpClientConnection>() {
+
+                    @Override
+                    public void process(final PoolEntry<HttpRoute, ManagedHttpClientConnection> entry) {
+                        final ManagedHttpClientConnection connection = entry.getConnection();
+                        if (connection != null) {
+                            try {
+                                connection.shutdown();
+                            } catch (final IOException iox) {
+                                if (log.isDebugEnabled()) {
+                                    log.debug("I/O exception shutting down connection", iox);
+                                }
+                            }
+                        }
+                    }
+
+                });
                 this.pool.shutdown();
             } catch (final IOException ex) {
                 this.log.debug("I/O exception shutting down connection manager", ex);
diff --git a/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java b/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
index 279793a..b64bb7e 100644
--- a/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
+++ b/httpclient/src/test/java/org/apache/http/impl/conn/TestBasicHttpClientConnectionManager.java
@@ -278,7 +278,7 @@ public class TestBasicHttpClientConnectionManager {
 
         mgr.shutdown();
 
-        Mockito.verify(conn, Mockito.times(1)).close();
+        Mockito.verify(conn, Mockito.times(1)).shutdown();
 
         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)).close();
+        Mockito.verify(conn, Mockito.times(1)).shutdown();
     }
 
     @Test