Subject: Re: libssh2_sftp_init() blocks and does not return

Re: libssh2_sftp_init() blocks and does not return

From: Heiner Steven <heiner.steven_at_nexgo.de>
Date: Mon, 23 Mar 2009 17:36:44 +0100

Daniel Stenberg wrote:
> On Sun, 22 Mar 2009, Heiner Steven wrote:
>
>>> What other alternatives can you think of? Did you try this against other
>>> SFTP servers?
>> I tested with the local Linux OpenSSH server (5.1) and with a Solaris 10
>> server, also with OpenSSH 5.0.
>
> Did you also try the 'example/simple/sftp_nonblock' tool to see if that shows
> the same problem?

Not yet.

>> [libssh2] 3.400569 Conn: Setting blocking mode on session 1
>
> Ouch - that will of course explain the hang! As I read the code, that is
> called by your app as I can't see anything within libssh2 that would change
> this. Can you?

Sorry, this was caused by my own code: when I disabled blocking for
these tests before calling libssh2_sftp_init() I also added code to
return the socket to blocking mode afterwards.

The problem is still there, though: the original code (calling
libssh2_sftp_init() with a blocking socket) still blocks in
libssh2_sftp_init.

When following the stacktrace

#0 0x00007f785e9260d5 in recv () from /lib/libc.so.6
#1 0x0000000000425f3b in _libssh2_packet_read (session=0xdd56b0)
     at src/lib/libssh2/src/transport.c:362
#2 0x0000000000410a66 in libssh2_channel_read_ex (channel=0xdde770,
     stream_id=0, buf=0x7fff679f0d60 " \016\237gÿ\177", buflen=4)
     at src/lib/libssh2/src/channel.c:1515
#3 0x000000000041ab80 in sftp_packet_read (sftp=0xddda20)
     at src/lib/libssh2/src/sftp.c:154
#4 0x000000000041b057 in sftp_packet_require (sftp=0xddda20,
     packet_type=2 '\002', request_id=0, data=0x7fff679f0e20,
     data_len=0x7fff679f0e18)
     at src/lib/libssh2/src/sftp.c:303
#5 0x000000000041bc33 in libssh2_sftp_init (session=0xdd56b0)
     at src/lib/libssh2/src/sftp.c:645
#6 0x0000000000408171 in getsftp (conn=0x635ef8, url=0xdd3e80)
     at src/smove/remoteops.c:580
#7 0x00000000004089ef in remote_fstat (connp=0x635ef8, url=0xdd3e80,
     mustexist=false) at src/smove/remoteops.c:963
#8 0x0000000000404942 in gen_fstat (connp=0x635ef8, url=0xdd3e80,
     mustexist=false) at src/smove/smove.c:850
#9 0x0000000000405b10 in main (argc=6, argv=0x7fff679f1b78)
     at src/smove/smove.c:1671

Item #5 caught my eye: line 645 in "sftp.c" looks as follows:

  644 /* For initiallization we are requiring blocking, probably reasonable * /
  645 rc = sftp_packet_require(session->sftpInit_sftp, SSH_FXP_VERSION,
  646 0, &data, &data_len);
  647 if (rc == PACKET_EAGAIN) {
  648 libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
  649 "Would block waiting for response from SFTP subsystem ",
  650 0);
  651 return NULL;
  652 } else if (rc) {
  653 libssh2_error(session, LIBSSH2_ERROR_SOCKET_TIMEOUT,
  654 "Timeout waiting for response from SFTP subsystem", 0 );

The comment indicates that the call to sftp_packet_require()
explicitly requires blocking.

Heiner

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2009-03-23