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 2025/09/13 16:38:59 UTC

(httpcomponents-core) 04/05: Bug fix: async i/o session to explicitly close the channel for output in GRACEFUL close mode

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 1558d2a5df013c145d89086d9b8104fe27dbf837
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Sep 13 16:34:51 2025 +0200

    Bug fix: async i/o session to explicitly close the channel for output in GRACEFUL close mode
---
 .../hc/core5/testing/extension/nio/H2AsyncServerResource.java      | 2 +-
 .../hc/core5/testing/extension/nio/HttpAsyncServerResource.java    | 2 +-
 .../src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java   | 7 ++++++-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/H2AsyncServerResource.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/H2AsyncServerResource.java
index 04f71d5b8..c5e2b823b 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/H2AsyncServerResource.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/H2AsyncServerResource.java
@@ -70,7 +70,7 @@ public void afterEach(final ExtensionContext extensionContext) throws Exception
         LOG.debug("Shutting down test server");
         if (server != null) {
             try {
-                server.close(CloseMode.IMMEDIATE);
+                server.close(CloseMode.GRACEFUL);
             } catch (final Exception ignore) {
             }
         }
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/HttpAsyncServerResource.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/HttpAsyncServerResource.java
index 15c97c300..dbb617620 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/HttpAsyncServerResource.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/extension/nio/HttpAsyncServerResource.java
@@ -69,7 +69,7 @@ public void afterEach(final ExtensionContext extensionContext) throws Exception
         LOG.debug("Shutting down test server");
         if (server != null) {
             try {
-                server.close(CloseMode.IMMEDIATE);
+                server.close(CloseMode.GRACEFUL);
             } catch (final Exception ignore) {
             }
         }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
index 9fb5a52b9..bb5c070a1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
@@ -207,7 +207,7 @@ public void setSocketTimeout(final Timeout timeout) {
 
     @Override
     public int read(final ByteBuffer dst) throws IOException {
-        return this.channel.read(dst);
+            return this.channel.read(dst);
     }
 
     @Override
@@ -270,6 +270,11 @@ public void close(final CloseMode closeMode) {
                 } catch (final UnsupportedOperationException | IOException e) {
                     // Quietly ignore
                 }
+            } else {
+                try {
+                    this.channel.shutdownOutput();
+                } catch (final IOException ignore) {
+                }
             }
             lock.lock();
             try {