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/19 13:27:37 UTC

[httpcomponents-core] 03/03: Move decision if the i/o session is to be terminated immediately to the protocol handler; by default attempt to terminate the i/o session gracefully

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 050c567d2e058b3e95c94c2a8fc7c6b6f3057eb5
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Thu Nov 19 12:29:22 2020 +0100

    Move decision if the i/o session is to be terminated immediately to the protocol handler; by default attempt to terminate the i/o session gracefully
---
 .../core5/http2/impl/nio/AbstractH2StreamMultiplexer.java  | 10 +++++++++-
 .../core5/http/impl/nio/AbstractHttp1StreamDuplexer.java   | 14 +++++++++++---
 .../java/org/apache/hc/core5/reactor/InternalChannel.java  |  4 ++--
 3 files changed, 22 insertions(+), 6 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 1c756fd..7524dea 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
@@ -689,7 +689,15 @@ abstract class AbstractH2StreamMultiplexer implements Identifiable, HttpConnecti
             connState = ConnectionHandshake.SHUTDOWN;
         } catch (final IOException ignore) {
         } finally {
-            ioSession.close(cause instanceof IOException ? CloseMode.IMMEDIATE : CloseMode.GRACEFUL);
+            final CloseMode closeMode;
+            if (cause instanceof ConnectionClosedException) {
+                closeMode = CloseMode.GRACEFUL;
+            } else if (cause instanceof IOException) {
+                closeMode = CloseMode.IMMEDIATE;
+            } else {
+                closeMode = CloseMode.GRACEFUL;
+            }
+            ioSession.close(closeMode);
         }
     }
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index c5e63d4..bf4d268 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -157,12 +157,20 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         }
     }
 
-    void shutdownSession(final Exception exception) {
+    void shutdownSession(final Exception cause) {
         connState = ConnectionState.SHUTDOWN;
         try {
-            terminate(exception);
+            terminate(cause);
         } finally {
-            ioSession.close();
+            final CloseMode closeMode;
+            if (cause instanceof ConnectionClosedException) {
+                closeMode = CloseMode.GRACEFUL;
+            } else if (cause instanceof IOException) {
+                closeMode = CloseMode.IMMEDIATE;
+            } else {
+                closeMode = CloseMode.GRACEFUL;
+            }
+            ioSession.close(closeMode);
         }
     }
 
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
index fce58bd..acf8c8a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalChannel.java
@@ -53,7 +53,7 @@ abstract class InternalChannel implements ModalCloseable {
             close(CloseMode.GRACEFUL);
         } catch (final Exception ex) {
             onException(ex);
-            close(CloseMode.IMMEDIATE);
+            close(CloseMode.GRACEFUL);
         }
     }
 
@@ -69,7 +69,7 @@ abstract class InternalChannel implements ModalCloseable {
                     close(CloseMode.GRACEFUL);
                 } catch (final Exception ex) {
                     onException(ex);
-                    close(CloseMode.IMMEDIATE);
+                    close(CloseMode.GRACEFUL);
                 }
                 return false;
             }