[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: sftp_write waits infinitely


Hello,


some more information.

I am using libssh 0.6.1 from ubuntu trusty.


The program's call stack when it waits infinitely:

0    __poll_nocancel    syscall-template.S    81    0x7ffff6063110
1    ssh_poll_ctx_dopoll    poll.c    604    0x7ffff5503479
2    ssh_handle_packets    session.c    547    0x7ffff5504339
3    ssh_handle_packets_termination    session.c    609    0x7ffff550441d
4    ssh_channel_read_timeout    channels.c    2801    0x7ffff54f10d2
5    ssh_channel_read    channels.c    2717    0x7ffff54f11db
6    sftp_packet_read    sftp.c    329    0x7ffff550a958
7    sftp_read_and_dispatch    sftp.c    468    0x7ffff550ace0
8    sftp_write    sftp.c    2006    0x7ffff550d168
9    ...


I do not understand this function, that is also part of my call stack:


int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
{
    return ssh_channel_read_timeout(channel, dest, count, is_stderr, -1);
}


So ssh_channel_read_timeout is always called with timeout=-1

Is this function we find:

if (timeout < 0) {
      timeout = SSH_TIMEOUT_DEFAULT;
}

rc = ssh_handle_packets_termination(session,
                                      timeout,
                                      ssh_channel_read_termination,
                                      &ctx);


So ssh_handle_packets_termination is always called with timeout=SSH_TIMEOUT_DEFAULT.

In this function there is:

if (timeout == SSH_TIMEOUT_USER) {
        ...
} else if (timeout == SSH_TIMEOUT_DEFAULT) {

        if (ssh_is_blocking(session)) {
            timeout = SSH_TIMEOUT_INFINITE;
        } else {
            timeout = SSH_TIMEOUT_NONBLOCKING;
        }

}

It will never run into the SSH_TIMEOUT_USER case but always use the SSH_TIMEOUT_INFINITE for nonblocking or SSH_TIMEOUT_NONBLOCKING which is 0. Is this a bug?

What part of the library really uses the timeout set with ssh_options_set(sshSession, SSH_OPTIONS_TIMEOUT, &timeout)?

Any help will be appreciated.


Best regards

Jakob Kohl


________________________________
Von: Jakob Kohl | nowcast GmbH <jkohl@xxxxxxxxxx>
Gesendet: Mittwoch, 17. Februar 2016 11:21
An: libssh@xxxxxxxxxx
Betreff: sftp_write waits infinitely


Hello,


I am having a problem with sftp transfer. I have the following test setup:

  1.  A machine which accepts ssh connections.
  2.  My machine which sets up connection to the first machine and transmits a large file.

During the transmission of the file I unplug the network cable of machine 1. Program on my machine waits somewhere in sftp_write.

After 20 minutes or so I plug the network cable.  Program still waits in sftp_write and will do this forever!

I debugged into this problem and noticed that ssh_channel_read_timeout is called with timeout = -1, which means infinite timeout.

I am using the default blocking ssh_session and sftp_file.

I am also using this:
int timeout = 10;
ssh_options_set(sshSession, SSH_OPTIONS_TIMEOUT, &timeout);
Setting the sftp file to nonblocking changes nothing as the nonblocking flag is only used for sftp file read.

When using ssh_set_blocking(sshSession, 0) even connecting the ssh session won't work!

So how do I implement a SFTP file transfer, which runs into a timeout of 10 seconds if connection is lost and then returns?



Best regards

Jakob Kohl
Software Entwicklung

[nowcast GmbH]


nowcast GmbH
Albert-Roßhaupter-Str. 43
81369 München

Phone: +49.(0)89.5529.713.85
Fax: +49.(0)89.5529.713.71

jakob.kohl@xxxxxxxxxx<mailto:jakob.kohl@xxxxxxxxxx>
www.nowcast.de<http://www.nowcast.de>

Geschäftsführung / Management Board: Alexander Betz, Irmtraud Königshofer
Sitz der Gesellschaft / Registered Office: München
Registergericht / Court of Registration: AG München, HRB 147454
USt.-Id: DE 233256369

Follow-Ups:
Re: sftp_write waits infinitelyAndreas Schneider <asn@xxxxxxxxxxxxxx>
References:
sftp_write waits infinitelyJakob Kohl | nowcast GmbH <jkohl@xxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org