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 2017/05/09 20:02:41 UTC

[12/34] httpcomponents-core git commit: HTTPASYNC-69: async request handler is closed by HttpAsyncRequestExecutor#closed if the underlying connection is found to be in an inconsistent state

HTTPASYNC-69: async request handler is closed by HttpAsyncRequestExecutor#closed if the underlying connection is found to be in an inconsistent state

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.3.x@1569023 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/8e0eca24
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/8e0eca24
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/8e0eca24

Branch: refs/heads/4.3.x
Commit: 8e0eca243c4fdba58b8253318cce181ce87329cb
Parents: e3c09c4
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Feb 17 15:32:35 2014 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Feb 17 15:32:35 2014 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                                | 10 ++++++++++
 .../nio/protocol/HttpAsyncRequestExecutor.java   | 10 +++++++---
 .../protocol/TestHttpAsyncRequestExecutor.java   | 19 +++++++++++++++----
 3 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8e0eca24/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 8de35a2..d652274 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -1,3 +1,13 @@
+Changes since Release 4.3.2
+-------------------
+
+* [HTTPASYNC-69]: async request handler is closed by HttpAsyncRequestExecutor#closed 
+  if the underlying connection is found to be in an inconsistent state.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
+
+
 Release 4.3.2
 -------------------
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8e0eca24/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
index 131b068..5dc806e 100644
--- a/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
+++ b/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
@@ -107,12 +107,16 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
     public void closed(final NHttpClientConnection conn) {
         final State state = getState(conn);
         final HttpAsyncClientExchangeHandler handler = getHandler(conn);
+        if (state != null) {
+            if (state.getRequestState() != MessageState.READY || state.getResponseState() != MessageState.READY) {
+                if (handler != null) {
+                    handler.failed(new ConnectionClosedException("Connection closed unexpectedly"));
+                }
+            }
+        }
         if (state == null || (handler != null && handler.isDone())) {
             closeHandler(handler);
         }
-        if (state != null) {
-            state.reset();
-        }
     }
 
     public void exception(

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8e0eca24/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java b/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
index d646f65..88373ee 100644
--- a/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
+++ b/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
@@ -101,15 +101,13 @@ public class TestHttpAsyncRequestExecutor {
     @Test
     public void testClosed() throws Exception {
         final State state = new HttpAsyncRequestExecutor.State();
-        state.setRequestState(MessageState.COMPLETED);
-        state.setResponseState(MessageState.COMPLETED);
+        state.setRequestState(MessageState.READY);
+        state.setResponseState(MessageState.READY);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         this.protocolHandler.closed(this.conn);
 
-        Assert.assertEquals(MessageState.READY, state.getRequestState());
-        Assert.assertEquals(MessageState.READY, state.getResponseState());
         Mockito.verify(this.exchangeHandler, Mockito.never()).close();
     }
 
@@ -123,6 +121,19 @@ public class TestHttpAsyncRequestExecutor {
     }
 
     @Test
+    public void testClosedInconsistentState() throws Exception {
+        final State state = new HttpAsyncRequestExecutor.State();
+        state.setRequestState(MessageState.COMPLETED);
+        state.setResponseState(MessageState.INIT);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
+
+        this.protocolHandler.closed(this.conn);
+
+        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
+    }
+
+    @Test
     public void testHttpExceptionHandling() throws Exception {
         final State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);