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 2019/07/28 21:07:13 UTC

[httpcomponents-core] 05/05: Fail request execution immediately after submission if the I/O session has already been closed.

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch bug-fixes
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git

commit a60528ea58877d55dab266bd2813e065aac6ff2c
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun Jul 28 23:06:27 2019 +0200

    Fail request execution immediately after submission if the I/O session has already been closed.
---
 .../hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java  | 4 ++++
 .../java/org/apache/hc/core5/testing/nio/ClientSessionEndpoint.java | 6 +++++-
 .../org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java | 4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
index f7a269d..39b6d64 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2MultiplexingRequester.java
@@ -42,6 +42,7 @@ import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Decorator;
 import org.apache.hc.core5.function.Resolver;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -224,6 +225,9 @@ public class H2MultiplexingRequester extends AsyncRequester{
                                 }
 
                             }, pushHandlerFactory, cancellableDependency, context), Command.Priority.NORMAL);
+                            if (ioSession.isClosed()) {
+                                exchangeHandler.failed(new ConnectionClosedException());
+                            }
                         }
 
                         @Override
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ClientSessionEndpoint.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ClientSessionEndpoint.java
index 6e88fb1..3672ae1 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ClientSessionEndpoint.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ClientSessionEndpoint.java
@@ -35,6 +35,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.concurrent.BasicFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
@@ -80,7 +81,10 @@ public final class ClientSessionEndpoint implements ModalCloseable {
             final HttpContext context) {
         Asserts.check(!closed.get(), "Connection is already closed");
         final Command executionCommand = new RequestExecutionCommand(exchangeHandler, pushHandlerFactory, null, context);
-        execute(executionCommand, Command.Priority.NORMAL);
+        ioSession.enqueue(executionCommand, Command.Priority.NORMAL);
+        if (ioSession.isClosed()) {
+            exchangeHandler.failed(new ConnectionClosedException());
+        }
     }
 
     public void execute(
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index 3d1bca1..c10a721 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -40,6 +40,7 @@ import org.apache.hc.core5.concurrent.ComplexFuture;
 import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.function.Decorator;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.EntityDetails;
 import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
@@ -432,6 +433,9 @@ public class HttpAsyncRequester extends AsyncRequester implements ConnPoolContro
                 throw new IllegalStateException("I/O session is invalid");
             }
             ioSession.enqueue(new RequestExecutionCommand(exchangeHandler, pushHandlerFactory, null, context), Command.Priority.NORMAL);
+            if (ioSession.isClosed()) {
+                exchangeHandler.failed(new ConnectionClosedException());
+            }
         }
 
         @Override