hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1364408 - in /httpcomponents/httpclient/branches/4.2.x: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
Date Sun, 22 Jul 2012 19:42:29 GMT
Author: olegk
Date: Sun Jul 22 19:42:29 2012
New Revision: 1364408

URL: http://svn.apache.org/viewvc?rev=1364408&view=rev
Log:
HTTPCLIENT-1217: AutoRetryHttpClient does not release connection used by the previous response
when request is retried

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1364408&r1=1364407&r2=1364408&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Sun Jul 22 19:42:29 2012
@@ -1,3 +1,10 @@
+Changes since 4.2.1
+
+* [HTTPCLIENT-1217] AutoRetryHttpClient does not release connection used by the previous
response 
+  when request is retried
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
 Release 4.2.1 
 -------------------
 

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java?rev=1364408&r1=1364407&r2=1364408&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/impl/client/AutoRetryHttpClient.java
Sun Jul 22 19:42:29 2012
@@ -44,6 +44,7 @@ import org.apache.http.client.methods.Ht
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
 
 /**
  * {@link HttpClient} implementation that can automatically retry the request in case of
@@ -154,16 +155,26 @@ public class AutoRetryHttpClient impleme
             HttpContext context) throws IOException {
         for (int c = 1;; c++) {
             HttpResponse response = backend.execute(target, request, context);
-            if (retryStrategy.retryRequest(response, c, context)) {
-                long nextInterval = retryStrategy.getRetryInterval();
+            try {
+                if (retryStrategy.retryRequest(response, c, context)) {
+                    EntityUtils.consume(response.getEntity());
+                    long nextInterval = retryStrategy.getRetryInterval();
+                    try {
+                        log.trace("Wait for " + nextInterval);
+                        Thread.sleep(nextInterval);
+                    } catch (InterruptedException e) {
+                        throw new InterruptedIOException(e.getMessage());
+                    }
+                } else {
+                    return response;
+                }
+            } catch (RuntimeException ex) {
                 try {
-                    log.trace("Wait for " + nextInterval);
-                    Thread.sleep(nextInterval);
-                } catch (InterruptedException e) {
-                    throw new InterruptedIOException(e.getMessage());
+                    EntityUtils.consume(response.getEntity());
+                } catch (IOException ioex) {
+                    log.warn("I/O error consuming response content", ioex);
                 }
-            } else {
-                return response;
+                throw ex;
             }
         }
     }



Mime
View raw message