Blame SOURCES/0004-partially-revert-window_size-explicit-adjustments-on.patch

68eb44
From 9e56b84c41efcaf3349f82a93c3dc854e172e5c4 Mon Sep 17 00:00:00 2001
68eb44
From: Kamil Dudka <kdudka@redhat.com>
68eb44
Date: Fri, 9 Aug 2013 16:22:08 +0200
68eb44
Subject: [PATCH 4/5] partially revert "window_size: explicit adjustments only"
68eb44
68eb44
This partially reverts commit 03ca9020756a4e16f0294e5b35e9826ee6af2364
68eb44
in order to fix extreme slowdown when uploading to localhost via SFTP.
68eb44
68eb44
I was able to repeat the issue on RHEL-7 on localhost only.  It did not
68eb44
occur when uploading via network and it did not occur on a RHEL-6 box
68eb44
with the same version of libssh2.
68eb44
68eb44
The problem was that sftp_read() used a read-ahead logic to figure out
68eb44
the window_size, but sftp_packet_read() called indirectly from
68eb44
sftp_write() did not use any read-ahead logic.
68eb44
---
68eb44
 src/channel.c |   29 +++++++++++++++++++++++++++++
68eb44
 1 files changed, 29 insertions(+), 0 deletions(-)
68eb44
68eb44
diff --git a/src/channel.c b/src/channel.c
68eb44
index 4f41e1f..d4ffdce 100644
68eb44
--- a/src/channel.c
68eb44
+++ b/src/channel.c
68eb44
@@ -1759,6 +1759,15 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
68eb44
         channel->read_state = libssh2_NB_state_created;
68eb44
     }
68eb44
 
68eb44
+    /*
68eb44
+     * =============================== NOTE ===============================
68eb44
+     * I know this is very ugly and not a really good use of "goto", but
68eb44
+     * this case statement would be even uglier to do it any other way
68eb44
+     */
68eb44
+    if (channel->read_state == libssh2_NB_state_jump1) {
68eb44
+        goto channel_read_window_adjust;
68eb44
+    }
68eb44
+
68eb44
     rc = 1; /* set to >0 to let the while loop start */
68eb44
 
68eb44
     /* Process all pending incoming packets in all states in order to "even
68eb44
@@ -1867,6 +1876,26 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
68eb44
            more off the network again */
68eb44
         channel->read_state = libssh2_NB_state_created;
68eb44
 
68eb44
+    if(channel->remote.window_size < (LIBSSH2_CHANNEL_WINDOW_DEFAULT*30)) {
68eb44
+        /* the window is getting too narrow, expand it! */
68eb44
+
68eb44
+      channel_read_window_adjust:
68eb44
+        channel->read_state = libssh2_NB_state_jump1;
68eb44
+        /* the actual window adjusting may not finish so we need to deal with
68eb44
+           this special state here */
68eb44
+        rc = _libssh2_channel_receive_window_adjust(channel,
68eb44
+                                                    (LIBSSH2_CHANNEL_WINDOW_DEFAULT*60), 0, NULL);
68eb44
+        if (rc)
68eb44
+            return rc;
68eb44
+
68eb44
+        _libssh2_debug(session, LIBSSH2_TRACE_CONN,
68eb44
+                       "channel_read() filled %d adjusted %d",
68eb44
+                       bytes_read, buflen);
68eb44
+        /* continue in 'created' state to drain the already read packages
68eb44
+           first before starting to empty the socket further */
68eb44
+        channel->read_state = libssh2_NB_state_created;
68eb44
+    }
68eb44
+
68eb44
     return bytes_read;
68eb44
 }
68eb44
 
68eb44
-- 
68eb44
1.7.1
68eb44