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 2013/07/03 10:41:05 UTC
svn commit: r1499262 - in /httpcomponents/httpcore/branches/4.2.x: ./
httpcore-nio/src/main/java/org/apache/http/nio/entity/
httpcore-nio/src/test/java/org/apache/http/nio/integration/
Author: olegk
Date: Wed Jul 3 08:41:05 2013
New Revision: 1499262
URL: http://svn.apache.org/r1499262
Log:
HTTPCORE-345: EntityAsyncContentProducer fails to release resources allocated by the underlying entity when #produceContent is never invoked
Contributed by Tad Whitenight <tadwhitenight at gmail.com
Modified:
httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
Modified: httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt?rev=1499262&r1=1499261&r2=1499262&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt Wed Jul 3 08:41:05 2013
@@ -1,6 +1,10 @@
Changes since Release 4.2.4
-------------------
+* [HTTPCORE-345] EntityAsyncContentProducer fails to release resources allocated by the underlying
+ entity when #produceContent is never invoked.
+ Contributed by Tad Whitenight <tadwhitenight at gmail.com>
+
* Non-blocking connection pool to avoid scanning the entire queue of pending connection requests
on each connection lease / release operation (under heavy load the request queue can contain
a significant number of pending requests, a full linear scan of which can cause massive
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java?rev=1499262&r1=1499261&r2=1499262&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java Wed Jul 3 08:41:05 2013
@@ -28,6 +28,7 @@
package org.apache.http.nio.entity;
import java.io.IOException;
+import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
@@ -86,6 +87,10 @@ public class EntityAsyncContentProducer
if (local != null) {
local.close();
}
+ if (this.entity.isStreaming()) {
+ InputStream instream = this.entity.getContent();
+ instream.close();
+ }
}
}
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java?rev=1499262&r1=1499261&r2=1499262&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java Wed Jul 3 08:41:05 2013
@@ -26,11 +26,14 @@
*/
package org.apache.http.nio.integration;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import org.apache.http.Consts;
import org.apache.http.HttpConnection;
import org.apache.http.HttpCoreNIOTestBase;
import org.apache.http.HttpException;
@@ -41,6 +44,7 @@ import org.apache.http.LoggingClientConn
import org.apache.http.LoggingServerConnectionFactory;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
@@ -178,6 +182,14 @@ public class TestHttpAsyncPrematureTermi
@Test
public void testConnectionTerminatedHandlingRequest() throws Exception {
+ final CountDownLatch responseStreamClosed = new CountDownLatch(1);
+ final InputStream testInputStream = new ByteArrayInputStream("all is well".getBytes(Consts.ASCII)) {
+ @Override
+ public void close() throws IOException {
+ responseStreamClosed.countDown();
+ super.close();
+ }
+ };
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
@@ -195,7 +207,7 @@ public class TestHttpAsyncPrematureTermi
ExecutionContext.HTTP_CONNECTION);
conn.shutdown();
HttpResponse response = httpExchange.getResponse();
- response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));
+ response.setEntity(new InputStreamEntity(testInputStream, -1));
httpExchange.submitResponse();
}
@@ -229,6 +241,7 @@ public class TestHttpAsyncPrematureTermi
this.connpool, context, callback);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+ Assert.assertTrue(responseStreamClosed.await(5, TimeUnit.SECONDS));
}
@Test