Subject: Re: [libssh2] #198: _libssh2_channel_close() may hang

Re: [libssh2] #198: _libssh2_channel_close() may hang

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Thu, 02 Dec 2010 14:24:57 -0000

#198: _libssh2_channel_close() may hang
---------------------+------------------------------------------------------
  Reporter: fd64 | Owner:
      Type: defect | Status: new
  Priority: normal | Milestone: 1.2.7
 Component: API | Version: 1.2.7
Resolution: | Keywords:
    Blocks: | Blocked By:
---------------------+------------------------------------------------------

Comment (by fd64):

 I have been testing the application with a patched libssh2 and I have not
 been able to reproduce this problem. This patch is certainly not the
 proper fix, but I just wanted to see if it still hangs when we limit the
 number of iteration of the loop when it hanged. So that's a good news,
 because with that modification libssh2 does not seem to hang any more even
 when it's running with very unreliable connections.

 If you could fix that problem in the upstream version, it would be great.

 Thanks

 Here is the patch:

 diff --git a/src/channel.c b/src/channel.c
 index ff1fb4d..bab8693 100644
 --- a/src/channel.c
 +++ b/src/channel.c
 @@ -2260,6 +2260,7 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL *
 channel)
      LIBSSH2_SESSION *session = channel->session;
      int rc = 0;
      int retcode;
 + int retries;

      if (channel->local.close) {
          /* Already closed, act like we sent another close,
 @@ -2304,7 +2305,8 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL *
 channel)
      if (channel->close_state == libssh2_NB_state_sent) {
          /* We must wait for the remote SSH_MSG_CHANNEL_CLOSE message */

 - while (!channel->remote.close && !rc) {
 + retries = 0;
 + while (!channel->remote.close && !rc && retries++ < 16) {
              rc = _libssh2_transport_read(session);
          }
      }

-- 
Ticket URL: <http://trac.libssh2.org/ticket/198#comment:1>
libssh2 <http://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-12-02