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/15 10:15:06 UTC

(httpcomponents-core) 01/02: Bug fix: race between async i/o session termination and command submission

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 ac42decdf5def442928de4f17eb8d54d3f12c066
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Mon Sep 15 10:53:51 2025 +0200

    Bug fix: race between async i/o session termination and command submission
---
 .../src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java    | 6 +++---
 .../src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java | 6 +++++-
 2 files changed, 8 insertions(+), 4 deletions(-)

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 afc4b87a9..dbe57c14d 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
@@ -107,9 +107,9 @@ public void enqueue(final Command command, final Command.Priority priority) {
         } else {
             commandQueue.add(command);
         }
-        setEvent(SelectionKey.OP_WRITE);
-
-        if (isStatusClosed()) {
+        if (status.get() == Status.ACTIVE) {
+            setEvent(SelectionKey.OP_WRITE);
+        } else {
             command.cancel();
         }
     }
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index a839d7ad4..4afaf2828 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -773,7 +773,11 @@ public void enqueue(final Command command, final Command.Priority priority) {
         this.session.getLock().lock();
         try {
             this.session.enqueue(command, priority);
-            setEvent(SelectionKey.OP_WRITE);
+            if (status == Status.ACTIVE) {
+                setEvent(SelectionKey.OP_WRITE);
+            } else {
+                command.cancel();
+            }
         } finally {
             this.session.getLock().unlock();
         }