Subject: Re: [libssh2] SFTP read hanging forever (LIBSSH2_ERROR_EAGAIN)

Re: [libssh2] SFTP read hanging forever (LIBSSH2_ERROR_EAGAIN)

From: James Housley <>
Date: Wed, 26 Sep 2007 06:38:13 -0400

On Sep 25, 2007, at 1:24 PM, wrote:

> Hi all,
> i'm facing two kind of problems that possibly are connected
> together in some way. These are basically related to a SFTP
> download using non blocking sockets (the file was about 2 Mega).
> What i noticed is that:
> 1) If i use a window size of 32768 at a certain point the
> libssh2_sftp_read returns a EAGAIN value forever. The select
> doesn't return any negative or zero values, meaning probably that
> the library is not reading anymore from the socket ... This problem
> presents itself in a quite random fashion, so sometimes the file is
> downloaded sometimes not.
> 2) Lowering the download windows size, library seems to work
> correctly. But i tried to do an experiment: while download was in
> progress i put the openSSH server offline (unpluggin the cable) the
> result was that the library libssh2_sftp_read returned a EAGAIN
> value forever, and the select didn't fail at all.
> I'm currently working as a client on a SUN Solaris 9 and as servers
> i tried on a linux machine and a HP-UX machine, both shipping
> openSSH servers.
> Please could you comment on those?
> I'm sending also my source code which follows very nearly the
> implementation of the example sftp_RW_nonblock

I have no if your problem is related to an issue I have found, but
have not been able to do more then a quick hack in libssh2_packet_add
(). The problem I was seeing is that for some specific data with a
specific server it was sending more uncompressed data then requested,
but less then the requested size compressed. I disabled this code at
packet.c:678 :

                 if (session->packAdd_channel->remote.packet_size <
                     (datalen - session->packAdd_data_head)) {
                      * Spec says we MAY ignore bytes sent beyond
                      * packet_size
                                   "Packet contains more data than we
offered to receive, truncating",
                     datalen =
                         session->packAdd_channel->remote.packet_size +

And things worked. I will post more and better information as soon
as I can.


/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
                 The Power to Serve
The wise man built his network upon Un*x.
     The foolish man built his network upon Windows.
This email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
libssh2-devel mailing list
Received on 2007-09-26