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 2018/12/07 18:23:58 UTC
httpcomponents-core git commit: Bug fix: corrected abnormal
termination of pipelined request sequence [Forced Update!]
Repository: httpcomponents-core
Updated Branches:
refs/heads/4.4.x 8811136ae -> e9a57dbed (forced update)
Bug fix: corrected abnormal termination of pipelined request sequence
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/e9a57dbe
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/e9a57dbe
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/e9a57dbe
Branch: refs/heads/4.4.x
Commit: e9a57dbed37222d65581d34bb592ae5cd837ac53
Parents: 4275744
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Fri Dec 7 19:18:39 2018 +0100
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Fri Dec 7 19:22:51 2018 +0100
----------------------------------------------------------------------
.../nio/protocol/HttpAsyncRequestExecutor.java | 29 ++++++++++++--------
.../TestHttpAsyncHandlersPipelining.java | 10 +++----
2 files changed, 22 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e9a57dbe/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 957952a..c65321e 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
@@ -120,6 +120,10 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
this(DEFAULT_WAIT_FOR_CONTINUE, null);
}
+ private static boolean pipelining(final HttpAsyncClientExchangeHandler handler) {
+ return handler.getClass().getAnnotation(Pipelined.class) != null;
+ }
+
@Override
public void connected(
final NHttpClientConnection conn,
@@ -132,16 +136,20 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
@Override
public void closed(final NHttpClientConnection conn) {
- final State state = getState(conn);
final HttpAsyncClientExchangeHandler handler = getHandler(conn);
+ if (handler == null) {
+ return;
+ }
+ final State state = getState(conn);
if (state != null) {
if (state.getRequestState() != MessageState.READY || state.getResponseState() != MessageState.READY) {
- if (handler != null) {
- handler.failed(new ConnectionClosedException("Connection closed unexpectedly"));
- }
+ handler.failed(new ConnectionClosedException("Connection closed unexpectedly"));
}
}
- if (state == null || (handler != null && handler.isDone())) {
+ if (!handler.isDone() && pipelining(handler)) {
+ handler.failed(new ConnectionClosedException("Connection closed unexpectedly"));
+ }
+ if (state == null || handler.isDone()) {
closeHandler(handler);
}
}
@@ -180,7 +188,7 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
return;
}
}
- final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
+ final boolean pipelined = pipelining(handler);
final HttpRequest request = handler.generateRequest();
if (request == null) {
@@ -241,8 +249,7 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
handler.produceContent(encoder, conn);
if (encoder.isCompleted()) {
handler.requestCompleted();
- final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
- state.setRequestState(pipelined ? MessageState.READY : MessageState.COMPLETED);
+ state.setRequestState(pipelining(handler) ? MessageState.READY : MessageState.COMPLETED);
}
}
@@ -257,9 +264,8 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
final HttpAsyncClientExchangeHandler handler = getHandler(conn);
Asserts.notNull(handler, "Client exchange handler");
- final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
final HttpRequest request;
- if (pipelined) {
+ if (pipelining(handler)) {
request = state.getRequestQueue().poll();
Asserts.notNull(request, "HTTP request");
} else {
@@ -441,8 +447,7 @@ public class HttpAsyncRequestExecutor implements NHttpClientEventHandler {
}
handler.responseCompleted();
- final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
- if (!pipelined) {
+ if (!pipelining(handler)) {
state.setRequestState(MessageState.READY);
state.setRequest(null);
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e9a57dbe/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java b/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
index a4c2586..53d3689 100644
--- a/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
+++ b/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
@@ -379,8 +379,8 @@ public class TestHttpAsyncHandlersPipelining extends HttpCoreNIOTestBase {
for (int i = 0; i < 3; i++) {
final HttpAsyncRequestProducer p1 = new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/"));
- final HttpAsyncRequestProducer p2 = new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/"));
- final HttpAsyncRequestProducer p3 = new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/boom"));
+ final HttpAsyncRequestProducer p2 = new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/boom"));
+ final HttpAsyncRequestProducer p3 = new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/"));
final List<HttpAsyncRequestProducer> requestProducers = new ArrayList<HttpAsyncRequestProducer>();
requestProducers.add(p1);
requestProducers.add(p2);
@@ -405,9 +405,9 @@ public class TestHttpAsyncHandlersPipelining extends HttpCoreNIOTestBase {
Assert.assertTrue(c1.isDone());
Assert.assertNotNull(c1.getResult());
Assert.assertTrue(c2.isDone());
- Assert.assertNotNull(c2.getResult());
- Assert.assertTrue(c2.isDone());
- Assert.assertNotNull(c3.getResult());
+// Assert.assertNotNull(c2.getResult());
+ Assert.assertTrue(c3.isDone());
+ Assert.assertNull(c3.getResult());
}
}