hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1198944 - in /httpcomponents/httpclient/branches/4.1.x: ./ httpclient-cache/ httpclient-cache/src/main/java/org/apache/http/client/cache/ httpclient-cache/src/main/java/org/apache/http/impl/client/cache/ httpclient-cache/src/test/java/org/...
Date Mon, 07 Nov 2011 21:20:20 GMT
Author: jonm
Date: Mon Nov  7 21:20:19 2011
New Revision: 1198944

URL: http://svn.apache.org/viewvc?rev=1198944&view=rev
Log:
HTTPCLIENT-1143: Backport to 4.1.x release branch.

Added:
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java
      - copied, changed from r1198939, httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java
Modified:
    httpcomponents/httpclient/branches/4.1.x/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.1.x/httpclient/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java
  (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java
  (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
    httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
    httpcomponents/httpclient/branches/4.1.x/httpclient-contrib/src/main/java/org/apache/http/contrib/auth/BouncySpnegoTokenGenerator.java
  (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpInetSocketAddress.java
  (props changed)
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/resources/test.keystore 
 (props changed)
    httpcomponents/httpclient/branches/4.1.x/src/docbkx/resources/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/src/site/   (props changed)
    httpcomponents/httpclient/branches/4.1.x/src/site/apt/ntlm.apt   (props changed)

Propchange: httpcomponents/httpclient/branches/4.1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,4 +1,4 @@
 /httpcomponents/httpclient/branches/4.0.x:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1:755593-811107
 /httpcomponents/httpclient/branches/notice-plugin-test:1024348-1031454
-/httpcomponents/httpclient/trunk:1087358,1091140-1091141,1091904,1104207-1104211,1132902-1132903,1133907,1138790-1138791,1147280
+/httpcomponents/httpclient/trunk:1087358,1091140-1091141,1091904,1104207-1104211,1132902-1132903,1133907,1138790-1138791,1147280,1198939,1198941

Modified: httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt?rev=1198944&r1=1198943&r2=1198944&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.1.x/RELEASE_NOTES.txt Mon Nov  7 21:20:19 2011
@@ -6,6 +6,9 @@ Changes since 4.1.2
 
 * [HTTPCLIENT-1127] Fixed deadlock between SingleClientConnManager.releaseConnection() and
   SingleClientConnManager.shutdown()
+  
+* [HTTPCLIENT-1143] CachingHttpClient leaks connections with stale-if-error.
+  Contributed by James Miller <jamesmiller01 at gmail dot com>
 
 Release 4.1.2
 -------------------

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,4 +1,4 @@
 /httpcomponents/httpclient/branches/4.0.x/httpclient:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1/httpclient:755593-811107
 /httpcomponents/httpclient/branches/notice-plugin-test/httpclient:1024348-1031454
-/httpcomponents/httpclient/trunk/httpclient:1087358,1088000-1088004,1091140-1091141,1091904,1100531-1100533,1104207-1104211,1132902-1132903,1138790-1138791,1147280
+/httpcomponents/httpclient/trunk/httpclient:1087358,1088000-1088004,1091140-1091141,1091904,1100531-1100533,1104207-1104211,1132902-1132903,1138790-1138791,1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,4 +1,4 @@
 /httpcomponents/httpclient/branches/4.0.x/httpclient-cache:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1/httpclient-cache:755593-811107
 /httpcomponents/httpclient/branches/notice-plugin-test/httpclient-cache:1024348-1031454
-/httpcomponents/httpclient/trunk/httpclient-cache:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1133907,1147280
+/httpcomponents/httpclient/trunk/httpclient-cache:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1133907,1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,3 +1,3 @@
 /httpcomponents/httpclient/branches/4.0.x/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCache.java:755593-811107
-/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1147280
+/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/client/cache/HttpCacheStorage.java:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,3 +1,3 @@
 /httpcomponents/httpclient/branches/4.0.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCache.java:755593-811107
-/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1147280
+/httpcomponents/httpclient/trunk/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/BasicHttpCacheStorage.java:1080419,1080422,1080575,1084590,1084607,1084610-1084611,1084649,1084655,1087358,1147280,1198939,1198941

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java?rev=1198944&r1=1198943&r2=1198944&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/main/java/org/apache/http/impl/client/cache/CachingHttpClient.java
Mon Nov  7 21:20:19 2011
@@ -37,6 +37,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpRequest;
@@ -63,6 +64,7 @@ import org.apache.http.impl.cookie.DateU
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
 import org.apache.http.util.VersionInfo;
 
 /**
@@ -821,7 +823,9 @@ public class CachingHttpClient implement
             && validityPolicy.mayReturnStaleIfError(request, cacheEntry, responseDate))
{
             final HttpResponse cachedResponse = responseGenerator.generateResponse(cacheEntry);
             cachedResponse.addHeader(HeaderConstants.WARNING, "110 localhost \"Response is
stale\"");
-            return cachedResponse; 
+            HttpEntity errorBody = backendResponse.getEntity();
+            if (errorBody != null) EntityUtils.consume(errorBody);
+            return cachedResponse;
         }
 
         return handleBackendResponse(target, conditionalRequest, requestDate, responseDate,

Copied: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java
(from r1198939, httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java?p2=httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java&p1=httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java&r1=1198939&r2=1198944&rev=1198944&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ConsumableInputStream.java
Mon Nov  7 21:20:19 2011
@@ -1,3 +1,29 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
 package org.apache.http.impl.client.cache;
 
 import java.io.ByteArrayInputStream;

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java?rev=1198944&r1=1198943&r2=1198944&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
(original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestRFC5861Compliance.java
Mon Nov  7 21:20:19 2011
@@ -27,13 +27,17 @@
 package org.apache.http.impl.client.cache;
 
 import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
 import java.util.Date;
 
 import org.apache.http.Header;
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
+import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.impl.cookie.DateUtils;
 import org.apache.http.message.BasicHttpRequest;
 import org.junit.Test;
@@ -84,6 +88,34 @@ public class TestRFC5861Compliance exten
     }
     
     @Test
+    public void testConsumesErrorResponseWhenServingStale()
+            throws Exception{
+        Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
+        HttpRequest req1 = HttpTestUtils.makeDefaultRequest();
+        HttpResponse resp1 = HttpTestUtils.make200Response(tenSecondsAgo,
+                "public, max-age=5, stale-if-error=60");
+
+        backendExpectsAnyRequest().andReturn(resp1);
+
+        HttpRequest req2 = HttpTestUtils.makeDefaultRequest();
+        HttpResponse resp2 = HttpTestUtils.make500Response();
+        byte[] body = HttpTestUtils.getRandomBytes(101);
+        ByteArrayInputStream buf = new ByteArrayInputStream(body);
+        ConsumableInputStream cis = new ConsumableInputStream(buf);
+        HttpEntity entity = new InputStreamEntity(cis, 101);
+        resp2.setEntity(entity);
+
+        backendExpectsAnyRequest().andReturn(resp2);
+
+        replayMocks();
+        impl.execute(host,req1);
+        impl.execute(host,req2);
+        verifyMocks();
+
+        assertTrue(cis.wasClosed());
+    }
+    
+    @Test
     public void testStaleIfErrorInResponseYieldsToMustRevalidate()
             throws Exception{
         Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient-contrib/src/main/java/org/apache/http/contrib/auth/BouncySpnegoTokenGenerator.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,2 +1,2 @@
 /httpcomponents/httpclient/branches/branch_4_1/contrib/org/apache/http/contrib/auth/BouncySpnegoTokenGenerator.java:755593-811107
-/httpcomponents/httpclient/trunk/httpclient-contrib/src/main/java/org/apache/http/contrib/auth/BouncySpnegoTokenGenerator.java:1087358,1147280
+/httpcomponents/httpclient/trunk/httpclient-contrib/src/main/java/org/apache/http/contrib/auth/BouncySpnegoTokenGenerator.java:1087358,1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/HttpInetSocketAddress.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -2,4 +2,4 @@
 /httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java:1079518-1080165
 /httpcomponents/httpclient/branches/branch_4_1/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java:755593-811107
 /httpcomponents/httpclient/branches/notice-plugin-test/httpclient/src/main/java/org/apache/http/conn/HttpInetSocketAddress.java:1024348-1031454
-/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpInetSocketAddress.java:1147280
+/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpInetSocketAddress.java:1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/httpclient/src/test/resources/test.keystore
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,2 +1,2 @@
-/httpcomponents/httpclient/trunk/httpclient/src/test/resources/test.keystore:1087358,1132902-1132903,1147280
+/httpcomponents/httpclient/trunk/httpclient/src/test/resources/test.keystore:1087358,1132902-1132903,1147280,1198939,1198941
 /httpcomponents/httpcore/branches/ibm_compat_branch/httpcore-nio/src/test/resources/test.keystore:755687-758898

Propchange: httpcomponents/httpclient/branches/4.1.x/src/docbkx/resources/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,2 +1,2 @@
-/httpcomponents/httpclient/trunk/src/docbkx/resources:1087358,1147280
+/httpcomponents/httpclient/trunk/src/docbkx/resources:1087358,1147280,1198939,1198941
 /httpcomponents/httpcore/branches/ibm_compat_branch/src/docbkx/resources:755687-758898

Propchange: httpcomponents/httpclient/branches/4.1.x/src/site/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1,4 +1,4 @@
 /httpcomponents/httpclient/branches/4.0.x/src/site:950681-950688
 /httpcomponents/httpclient/branches/branch_4_1/src/site:755593-811107
 /httpcomponents/httpclient/branches/notice-plugin-test/src/site:1024348-1031454
-/httpcomponents/httpclient/trunk/src/site:1087358,1091140-1091141,1091904,1095921-1100531,1147280
+/httpcomponents/httpclient/trunk/src/site:1087358,1091140-1091141,1091904,1095921-1100531,1147280,1198939,1198941

Propchange: httpcomponents/httpclient/branches/4.1.x/src/site/apt/ntlm.apt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov  7 21:20:19 2011
@@ -1 +1 @@
-/httpcomponents/httpclient/trunk/src/site/apt/ntlm.apt:825864-828185,954258,956989-957002,1147280
+/httpcomponents/httpclient/trunk/src/site/apt/ntlm.apt:825864-828185,954258,956989-957002,1147280,1198939,1198941



Mime
View raw message