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

tomaswolf pushed a commit to branch rc-3.0.0-M5
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 454d50c39e6c92ad52047dd1b0d588aca1f4aef5
Author: Thomas Wolf <[email protected]>
AuthorDate: Sat Jun 27 11:58:49 2026 +0200

    Avoid potential race at end of proxy protocol
    
    Removing the output handler in the ClientProxyFilter before having
    cleared the queue might theoretically lead to a case where a later
    message could overtake one of the queued messages. It's a highly
    unlikely race, but it's better to avoid it altogether.
---
 .../org/apache/sshd/client/session/filter/ClientProxyFilter.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/session/filter/ClientProxyFilter.java
 
b/sshd-core/src/main/java/org/apache/sshd/client/session/filter/ClientProxyFilter.java
index 599db2711..20965481f 100644
--- 
a/sshd-core/src/main/java/org/apache/sshd/client/session/filter/ClientProxyFilter.java
+++ 
b/sshd-core/src/main/java/org/apache/sshd/client/session/filter/ClientProxyFilter.java
@@ -65,6 +65,9 @@ public class ClientProxyFilter extends IoFilter {
 
     private final SshFutureListener<CloseFuture> closer;
 
+    // Concurrent access guarded by the monitor of 'queue'.
+    private boolean proxyProtocolDone;
+
     public ClientProxyFilter(AbstractClientSession session, ProxyData proxy, 
InetSocketAddress targetAddress) {
         this.session = Objects.requireNonNull(session);
         connector = proxy.getType() == Proxy.Type.SOCKS
@@ -120,7 +123,7 @@ public class ClientProxyFilter extends IoFilter {
                     }
                     input.set(null);
                     synchronized (queue) {
-                        output.set(null);
+                        proxyProtocolDone = true;
                         for (;;) {
                             Runnable send = queue.poll();
                             if (send == null) {
@@ -148,7 +151,7 @@ public class ClientProxyFilter extends IoFilter {
                 connector.start();
             }
             synchronized (queue) {
-                if (output.get() != null) {
+                if (!proxyProtocolDone) {
                     DefaultIoWriteFuture result = new 
DefaultIoWriteFuture(this, null);
                     queue.add(() -> {
                         try {
@@ -162,7 +165,7 @@ public class ClientProxyFilter extends IoFilter {
                     return result;
                 }
             }
-            return owner().send(cmd, message);
+            return owner().send(cmd, message).addListener(f -> 
output.set(null));
         }
 
     }

Reply via email to