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:51:29 UTC
svn commit: r1499271 - in /httpcomponents/httpcore/trunk: ./
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:51:29 2013
New Revision: 1499271
URL: http://svn.apache.org/r1499271
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/trunk/RELEASE_NOTES.txt
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1499271&r1=1499270&r2=1499271&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Wed Jul 3 08:51:29 2013
@@ -1,5 +1,10 @@
Changes since Release 4.3-BETA2
-------------------
+
+* [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>
+
* [HTTPCORE-343] AbstractNIOConnPool to fire request callbacks outside the pool lock.
This makes it possible to re-enter pool methods from a callback event.
Contributed by Oleg Kalnichevski <olegk at apache.org>
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java?rev=1499271&r1=1499270&r2=1499271&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/entity/EntityAsyncContentProducer.java Wed Jul 3 08:51:29 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;
@@ -85,6 +86,10 @@ public class EntityAsyncContentProducer
if (local != null) {
local.close();
}
+ if (this.entity.isStreaming()) {
+ final InputStream instream = this.entity.getContent();
+ instream.close();
+ }
}
}
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java?rev=1499271&r1=1499270&r2=1499271&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java Wed Jul 3 08:51:29 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.HttpException;
import org.apache.http.HttpHost;
@@ -38,6 +41,7 @@ import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
+import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.message.BasicHttpRequest;
@@ -158,6 +162,15 @@ public class TestHttpAsyncPrematureTermi
@Test
public void testConnectionTerminatedHandlingRequest() throws Exception {
final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
+ final CountDownLatch responseStreamClosed = new CountDownLatch(1);
+ final InputStream testInputStream = new ByteArrayInputStream(
+ "all is well".getBytes(Consts.ASCII.name())) {
+ @Override
+ public void close() throws IOException {
+ responseStreamClosed.countDown();
+ super.close();
+ }
+ };
registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -174,7 +187,7 @@ public class TestHttpAsyncPrematureTermi
HttpCoreContext.HTTP_CONNECTION);
conn.shutdown();
final HttpResponse response = httpExchange.getResponse();
- response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));
+ response.setEntity(new InputStreamEntity(testInputStream, -1));
httpExchange.submitResponse();
}
@@ -205,6 +218,7 @@ public class TestHttpAsyncPrematureTermi
this.client.execute(target, request, context, callback);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
+ Assert.assertTrue(responseStreamClosed.await(5, TimeUnit.SECONDS));
}
@Test