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/02/17 17:34:03 UTC

(httpcomponents-core) branch 5.3.x updated (18751e953 -> d36c9b0b7)

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

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


    from 18751e953 Bug fix: Corrected handling of invalid HTTP protocol version by HTTP/1.1 async client protocol handler
     new e542095df Bug fix: Shared output buffer #writeCompleted fails to signal end of stream correctly when there is no buffered data
     new d36c9b0b7 Bug-fix: Corrected message stream termination by the async HTTP/1.1 protocol handler when the connection has been half-closed by the opposite endpoint

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../http/impl/nio/ClientHttp1StreamHandler.java    |  2 +-
 .../http/impl/nio/ServerHttp1StreamHandler.java    |  2 +-
 .../nio/support/classic/SharedOutputBuffer.java    | 25 ++++++++++++++--------
 3 files changed, 18 insertions(+), 11 deletions(-)


(httpcomponents-core) 02/02: Bug-fix: Corrected message stream termination by the async HTTP/1.1 protocol handler when the connection has been half-closed by the opposite endpoint

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d36c9b0b727babd86d0d6ea358a99f5eb7554466
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Feb 17 15:51:01 2025 +0100

    Bug-fix: Corrected message stream termination by the async HTTP/1.1 protocol handler when the connection has been half-closed by the opposite endpoint
---
 .../org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java     | 2 +-
 .../org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index 18cc5af96..56c57b627 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -92,10 +92,10 @@ public void requestOutput() {
             @Override
             public void endStream(final List<? extends Header> trailers) throws IOException {
                 requestState = MessageState.COMPLETE;
+                outputChannel.complete(trailers);
                 if (!keepAlive && responseState == MessageState.COMPLETE) {
                     outputChannel.close();
                 }
-                outputChannel.complete(trailers);
             }
 
             @Override
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
index 4d2fa9115..8367bac89 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
@@ -102,8 +102,8 @@ public void requestOutput() {
 
             @Override
             public void endStream(final List<? extends Header> trailers) throws IOException {
-                outputChannel.complete(trailers);
                 responseState = MessageState.COMPLETE;
+                outputChannel.complete(trailers);
                 if (requestState == MessageState.COMPLETE && !keepAlive) {
                     outputChannel.close();
                 }


(httpcomponents-core) 01/02: Bug fix: Shared output buffer #writeCompleted fails to signal end of stream correctly when there is no buffered data

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e542095dfaf716f02d6f67359ccf2dfe82c7204b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Feb 1 14:45:57 2025 +0100

    Bug fix: Shared output buffer #writeCompleted fails to signal end of stream correctly when there is no buffered data
---
 .../nio/support/classic/SharedOutputBuffer.java    | 25 ++++++++++++++--------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedOutputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedOutputBuffer.java
index 1db488319..fb8dffba0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedOutputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/classic/SharedOutputBuffer.java
@@ -56,11 +56,6 @@ public SharedOutputBuffer(final int bufferSize) {
         this(new ReentrantLock(), bufferSize);
     }
 
-    @Override
-    public boolean isEndStream() {
-        return endStreamPropagated.get();
-    }
-
     public void flush(final DataStreamChannel channel) throws IOException {
         lock.lock();
         try {
@@ -71,9 +66,7 @@ public void flush(final DataStreamChannel channel) throws IOException {
                 dataStreamChannel.write(buffer());
             }
             if (!buffer().hasRemaining() && endStream) {
-                if (endStreamPropagated.compareAndSet(false, true)) {
-                    dataStreamChannel.endStream();
-                }
+                propagateEndStream();
             }
             condition.signalAll();
         } finally {
@@ -140,7 +133,15 @@ public void writeCompleted() throws IOException {
         try {
             if (!endStream) {
                 endStream = true;
-                waitEndStream();
+                if (dataStreamChannel != null) {
+                    setOutputMode();
+                    if (buffer().hasRemaining()) {
+                        dataStreamChannel.requestOutput();
+                        waitEndStream();
+                    } else {
+                        propagateEndStream();
+                    }
+                }
             }
         } finally {
             lock.unlock();
@@ -177,4 +178,10 @@ private void waitForSignal() throws InterruptedIOException {
         }
     }
 
+    private void propagateEndStream() throws IOException {
+        if (endStreamPropagated.compareAndSet(false, true)) {
+            dataStreamChannel.endStream();
+        }
+    }
+
 }