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 2020/11/21 17:20:53 UTC

[httpcomponents-core] 01/02: Improved detection of disconnected endpoints by HttpAsyncRequester

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

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

commit a1b92d0a329d1c24f5495b7fc86fc2af5b78d6bf
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Nov 21 14:06:58 2020 +0100

    Improved detection of disconnected endpoints by HttpAsyncRequester
---
 .../hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java      | 2 +-
 .../apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java   | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
index 7524dea..a3961b2 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractH2StreamMultiplexer.java
@@ -686,9 +686,9 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
                     commitFrame(goAway);
                 }
             }
-            connState = ConnectionHandshake.SHUTDOWN;
         } catch (final IOException ignore) {
         } finally {
+            connState = ConnectionHandshake.SHUTDOWN;
             final CloseMode closeMode;
             if (cause instanceof ConnectionClosedException) {
                 closeMode = CloseMode.GRACEFUL;
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 e31f546..5260da7 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
@@ -44,6 +44,7 @@ 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.HttpConnection;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
@@ -73,6 +74,7 @@ import org.apache.hc.core5.pool.ManagedConnPool;
 import org.apache.hc.core5.pool.PoolEntry;
 import org.apache.hc.core5.pool.PoolStats;
 import org.apache.hc.core5.reactor.Command;
+import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
@@ -473,7 +475,11 @@ public class HttpAsyncRequester extends AsyncRequester implements ConnPoolContro
             final PoolEntry<HttpHost, IOSession> poolEntry = poolEntryRef.get();
             if (poolEntry != null) {
                 final IOSession ioSession = poolEntry.getConnection();
-                return ioSession != null && ioSession.isOpen();
+                if (ioSession == null || !ioSession.isOpen()) {
+                    return false;
+                }
+                final IOEventHandler handler = ioSession.getHandler();
+                return (handler instanceof HttpConnection) && ((HttpConnection) handler).isOpen();
             }
             return false;
         }