hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1569026 - in /httpcomponents/httpasyncclient/trunk: ./ httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ httpasyncclient/src/main/java/org/apache/http/nio/client/methods/
Date Mon, 17 Feb 2014 15:38:30 GMT
Author: olegk
Date: Mon Feb 17 15:38:30 2014
New Revision: 1569026

URL: http://svn.apache.org/r1569026
Log:
HTTPASYNC-69: premature cancellation of response consumer to immediately shut down and release
the underlying connection

Modified:
    httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java

Modified: httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt?rev=1569026&r1=1569025&r2=1569026&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpasyncclient/trunk/RELEASE_NOTES.txt Mon Feb 17 15:38:30 2014
@@ -1,6 +1,10 @@
 Changes since 4.0
 -------------------
 
+* [HTTPASYNC-69] Premature cancellation of the response consumer to immediately shut down
+  and release the underlying connection.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPASYNC-68] Connection closed by the opposite endpoint immediately upon its lease from
   the pool is never released back and reclaimed by the pool (collection leak).
   Contributed by Dmitry Potapov <potapov.d at gmail.com>

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java?rev=1569026&r1=1569025&r2=1569026&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
Mon Feb 17 15:38:30 2014
@@ -151,6 +151,13 @@ class DefaultClientExchangeHandlerImpl<T
     public void consumeContent(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
         this.exec.consumeContent(this.state, decoder, ioctrl);
+        if (!decoder.isCompleted() && this.responseConsumer.isDone()) {
+            if (this.completed.compareAndSet(false, true)) {
+                this.resultFuture.cancel();
+            }
+            this.state.setNonReusable();
+            releaseConnection();
+        }
     }
 
     public void responseCompleted() throws IOException, HttpException {

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java?rev=1569026&r1=1569025&r2=1569026&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
Mon Feb 17 15:38:30 2014
@@ -91,7 +91,7 @@ public abstract class AsyncByteConsumer<
         } else {
             iosession = null;
         }
-        for (;;) {
+        while (!this.isDone()) {
             final int bytesRead = decoder.read(this.bbuf);
             if (bytesRead <= 0) {
                 break;
@@ -99,8 +99,13 @@ public abstract class AsyncByteConsumer<
             this.bbuf.flip();
             onByteReceived(this.bbuf, ioctrl);
             this.bbuf.clear();
-            if (iosession != null && (iosession.getEventMask() & SelectionKey.OP_READ)
== 0) {
+            if (decoder.isCompleted()) {
                 break;
+            } else {
+                if (iosession != null && (iosession.isClosed()
+                        || (iosession.getEventMask() & SelectionKey.OP_READ) == 0)) {
+                    break;
+                }
             }
         }
     }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java?rev=1569026&r1=1569025&r2=1569026&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
Mon Feb 17 15:38:30 2014
@@ -106,7 +106,7 @@ public abstract class AsyncCharConsumer<
         } else {
             iosession = null;
         }
-        for (;;) {
+        while (!this.isDone()) {
             final int bytesRead = decoder.read(this.bbuf);
             if (bytesRead <= 0) {
                 break;
@@ -119,9 +119,12 @@ public abstract class AsyncCharConsumer<
             if (completed) {
                 result = this.chardecoder.flush(this.cbuf);
                 handleDecodingResult(result, ioctrl);
-            }
-            if (iosession != null && (iosession.getEventMask() & SelectionKey.OP_READ)
== 0) {
                 break;
+            } else {
+                if (iosession != null && (iosession.isClosed() ||
+                        (iosession.getEventMask() & SelectionKey.OP_READ) == 0)) {
+                    break;
+                }
             }
         }
     }



Mime
View raw message