hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject httpcomponents-client git commit: HTTPCLIENT-1879: re-apply SocketConfig#socketTimeout to connections leased by the pooling and basic connection managers
Date Thu, 16 Nov 2017 19:20:14 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.5.x 2e303b854 -> d6db9ab3d


HTTPCLIENT-1879: re-apply SocketConfig#socketTimeout to connections leased by the pooling
and basic connection managers


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/d6db9ab3
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/d6db9ab3
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/d6db9ab3

Branch: refs/heads/4.5.x
Commit: d6db9ab3d079b44e0a524dacf5e7ce9463618950
Parents: 2e303b8
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Thu Nov 16 20:17:16 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Thu Nov 16 20:17:36 2017 +0100

----------------------------------------------------------------------
 .../conn/BasicHttpClientConnectionManager.java  |  2 ++
 .../PoolingHttpClientConnectionManager.java     | 36 ++++++++++++++------
 2 files changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/d6db9ab3/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
----------------------------------------------------------------------
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 08153cd..5f69443 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
@@ -258,6 +258,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
         if (this.conn == null) {
             this.conn = this.connFactory.create(route, this.connConfig);
         }
+        this.conn.setSocketTimeout(this.socketConfig.getSoTimeout());
         this.leased = true;
         return this.conn;
     }
@@ -284,6 +285,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
                 this.expiry = Long.MAX_VALUE;
             } else {
                 this.state = state;
+                this.conn.setSocketTimeout(0);
                 if (this.log.isDebugEnabled()) {
                     final String s;
                     if (keepalive > 0) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/d6db9ab3/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
----------------------------------------------------------------------
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 81928ac..b20e024 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
@@ -28,7 +28,6 @@ package org.apache.http.impl.conn;
 
 import java.io.Closeable;
 import java.io.IOException;
-import java.net.InetSocketAddress;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -246,6 +245,17 @@ public class PoolingHttpClientConnectionManager
         return buf.toString();
     }
 
+    private SocketConfig resolveSocketConfig(final HttpHost host) {
+        SocketConfig socketConfig = this.configData.getSocketConfig(host);
+        if (socketConfig == null) {
+            socketConfig = this.configData.getDefaultSocketConfig();
+        }
+        if (socketConfig == null) {
+            socketConfig = SocketConfig.DEFAULT;
+        }
+        return socketConfig;
+    }
+
     @Override
     public ConnectionRequest requestConnection(
             final HttpRoute route,
@@ -266,7 +276,18 @@ public class PoolingHttpClientConnectionManager
             public HttpClientConnection get(
                     final long timeout,
                     final TimeUnit tunit) throws InterruptedException, ExecutionException,
ConnectionPoolTimeoutException {
-                return leaseConnection(future, timeout, tunit);
+                final HttpClientConnection conn = leaseConnection(future, timeout, tunit);
+                if (conn.isOpen()) {
+                    final HttpHost host;
+                    if (route.getProxyHost() != null) {
+                        host = route.getProxyHost();
+                    } else {
+                        host = route.getTargetHost();
+                    }
+                    final SocketConfig socketConfig = resolveSocketConfig(host);
+                    conn.setSocketTimeout(socketConfig.getSoTimeout());
+                }
+                return conn;
             }
 
         };
@@ -319,6 +340,7 @@ public class PoolingHttpClientConnectionManager
                         }
                         this.log.debug("Connection " + format(entry) + " can be kept alive
" + s);
                     }
+                    conn.setSocketTimeout(0);
                 }
             } finally {
                 this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
@@ -348,16 +370,8 @@ public class PoolingHttpClientConnectionManager
         } else {
             host = route.getTargetHost();
         }
-        final InetSocketAddress localAddress = route.getLocalSocketAddress();
-        SocketConfig socketConfig = this.configData.getSocketConfig(host);
-        if (socketConfig == null) {
-            socketConfig = this.configData.getDefaultSocketConfig();
-        }
-        if (socketConfig == null) {
-            socketConfig = SocketConfig.DEFAULT;
-        }
         this.connectionOperator.connect(
-                conn, host, localAddress, connectTimeout, socketConfig, context);
+                conn, host, route.getLocalSocketAddress(), connectTimeout, resolveSocketConfig(host),
context);
     }
 
     @Override


Mime
View raw message