From de0048759b871ee61bbd98619daff16be95a3e67 Mon Sep 17 00:00:00 2001
From: rolag <10981866+rolag@users.noreply.github.com>
Date: Fri, 27 Sep 2024 15:52:47 +0000
Subject: [PATCH] Fix unstable connections over nonblocking sockets (#1454)
 
 The `send_existing()` function allows partially sent packets to be sent
 fully before any further packets are sent. Originally this returned
 `LIBSSH2_ERROR_BAD_USE` when a different caller or thread tried to send
 an existing packet created by a different caller or thread causing the
 connection to disconnect. Commit 33dddd2f8ac3bc81 removed the return
 allowing any caller to continue sending another caller's packet. This
 caused connection instability as discussed in #1397 and confused the
 client and server causing occasional duplicate packets to be sent and
 giving the error `rcvd too much data` as discussed in #1431. We return
 `LIBSSH2_ERROR_EAGAIN` instead to allow existing callers to finish
 sending their own packets.
 
 Fixes #1397
 Fixes #1431
 Related #720
 
 Credit: klux21, rolag

Conflict:NA
Reference:https://github.com/libssh2/libssh2/commit/de0048759b871ee61bbd98619daff16be95a3e67

---
 src/transport.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/transport.c b/src/transport.c
index 3b30ff8..bbe7f5b 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -782,7 +782,8 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data,
            make the caller really notice his/hers flaw, we return error for
            this case */
         _libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
-                       "Address is different, but will resume nonetheless"));
+                       "Address is different, returning EAGAIN"));
+        return LIBSSH2_ERROR_EAGAIN;
     }
 
     *ret = 1;                   /* set to make our parent return */
-- 
2.43.0

