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: Fixed NPE PoolingAsyncClientConnectionManager
Date Wed, 09 Aug 2017 18:28:56 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/master a10967a42 -> 272ea1fa8


Fixed NPE PoolingAsyncClientConnectionManager

PoolingAsyncClientConnectionManager.validateAfterInactivity causes
an NPE when PoolEntries are initially created with no Connection.

Added logic to avoid checking the connection on every pool
checkout similar to the blocking pool.

Added an connection.isOpen check to http1.x connections leased
from the pool, although I'm unsure if it's at all effective.

Closes PR #82


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

Branch: refs/heads/master
Commit: 272ea1fa8337756e4e15b8c92745ec0a57293de3
Parents: a10967a
Author: Carter Kozak <c4kofony@gmail.com>
Authored: Wed Aug 9 11:27:28 2017 -0400
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed Aug 9 20:28:18 2017 +0200

----------------------------------------------------------------------
 .../impl/nio/PoolingAsyncClientConnectionManager.java    | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/272ea1fa/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
----------------------------------------------------------------------
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
index e7039ea..25dbae9 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java
@@ -164,8 +164,9 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
 
                     @Override
                     public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection>
poolEntry) {
-                        if (TimeValue.isPositive(validateAfterInactivity)) {
-                            final ManagedAsyncClientConnection connection = poolEntry.getConnection();
+                        final ManagedAsyncClientConnection connection = poolEntry.getConnection();
+                        if (TimeValue.isPositive(validateAfterInactivity) && connection
!= null &&
+                                poolEntry.getUpdated() + validateAfterInactivity.toMillis()
<= System.currentTimeMillis()) {
                             final ProtocolVersion protocolVersion = connection.getProtocolVersion();
                             if (HttpVersion.HTTP_2_0.greaterEquals(protocolVersion)) {
                                 connection.submitPriorityCommand(new PingCommand(new BasicPingHandler(new
Callback<Boolean>() {
@@ -183,6 +184,12 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio
 
                                 })));
                             } else {
+                                if (!connection.isOpen()) {
+                                    if (log.isDebugEnabled()) {
+                                        log.debug("Connection " + ConnPoolSupport.getId(connection)
+ " is closed");
+                                    }
+                                    poolEntry.discardConnection(ShutdownType.IMMEDIATE);
+                                }
                                 leaseCompleted(poolEntry);
                             }
                         } else {


Mime
View raw message