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 2017/05/09 20:03:25 UTC

[34/50] httpcomponents-core git commit: NIO connection pool was found to stop processing of pending requests prematurely (for instance, upon a request timeout) which could lead to unnecessary delays in connection allocation. When processing the next pend

NIO connection pool was found to stop processing of pending requests prematurely (for instance, upon a request timeout) which could lead to unnecessary delays in connection allocation. When processing the next pending request the pool should continue iterating over pending requests until one of two conditions is met: a pending request has been successfully handled by either allocating a persistent connection or by requesting a new connection or the queue has been fully exhausted.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.2.x@1489445 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/4.2.x
Commit: d73a24ea77d11487bd085a4d7e79762fb0f02beb
Parents: f8431ca
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Tue Jun 4 13:48:39 2013 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Tue Jun 4 13:48:39 2013 +0000

----------------------------------------------------------------------
 .../org/apache/http/nio/pool/AbstractNIOConnPool.java  | 13 +++++++++----
 .../java/org/apache/http/nio/pool/LeaseRequest.java    |  4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d73a24ea/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
index 2344a96..975cad9 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/pool/AbstractNIOConnPool.java
@@ -187,7 +187,8 @@ public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>>
             long timeout = connectTimeout > 0 ? tunit.toMillis(connectTimeout) : 0;
             BasicFuture<E> future = new BasicFuture<E>(callback);
             LeaseRequest<T, C, E> request = new LeaseRequest<T, C, E>(route, state, timeout, future);
-            if (!processPendingRequest(request)) {
+            boolean completed = processPendingRequest(request);
+            if (!request.isDone() && !completed) {
                 this.leasingRequests.add(request);
             }
             return future;
@@ -232,7 +233,8 @@ public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>>
         ListIterator<LeaseRequest<T, C, E>> it = this.leasingRequests.listIterator();
         while (it.hasNext()) {
             LeaseRequest<T, C, E> request = it.next();
-            if (processPendingRequest(request)) {
+            processPendingRequest(request);
+            if (request.isDone()) {
                 it.remove();
             }
         }
@@ -242,8 +244,11 @@ public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>>
         ListIterator<LeaseRequest<T, C, E>> it = this.leasingRequests.listIterator();
         while (it.hasNext()) {
             LeaseRequest<T, C, E> request = it.next();
-            if (processPendingRequest(request)) {
+            boolean completed = processPendingRequest(request);
+            if (request.isDone() || completed) {
                 it.remove();
+            }
+            if (completed) {
                 return;
             }
         }
@@ -258,7 +263,7 @@ public abstract class AbstractNIOConnPool<T, C, E extends PoolEntry<T, C>>
         long now = System.currentTimeMillis();
         if (now > deadline) {
             future.failed(new TimeoutException());
-            return true;
+            return false;
         }
 
         RouteSpecificPool<T, C, E> pool = getPool(route);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/d73a24ea/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java b/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
index 629f25f..d77d1c3 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/pool/LeaseRequest.java
@@ -73,6 +73,10 @@ class LeaseRequest<T, C, E extends PoolEntry<T, C>> {
         return this.future;
     }
 
+    public boolean isDone() {
+        return this.future.isDone();
+    }
+
     @Override
     public String toString() {
         StringBuilder buffer = new StringBuilder();