From b45e9818cc56d38fce5714ba0c3d566ab96c53c5 Mon Sep 17 00:00:00 2001 From: yhzdys Date: Wed, 16 Oct 2024 15:13:03 +0800 Subject: [PATCH] Bug fix: Correct the issue with connection state detection in DefaultManagedAsyncClientConnection#isOpen(). --- .../nio/DefaultManagedAsyncClientConnection.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java index e7142092f..e50cec04e 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/DefaultManagedAsyncClientConnection.java @@ -98,7 +98,20 @@ final class DefaultManagedAsyncClientConnection implements ManagedAsyncClientCon @Override public boolean isOpen() { - return ioSession.isOpen(); + final IOSession ioSession = this.ioSession; + if (ioSession.isOpen()) { + final IOEventHandler handler = ioSession.getHandler(); + if (handler instanceof HttpConnection) { + final HttpConnection conn = (HttpConnection) handler; + final ProtocolVersion protocolVersion = conn.getProtocolVersion(); + if (protocolVersion != null && protocolVersion.greaterEquals(HttpVersion.HTTP_2)) { + return conn.isOpen(); + } + } + return true; + } else { + return false; + } } @Override