New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fd gets closed twice when using libssh for sftp #8708
Comments
That seems like a reasonable assumption from a brief skim of the code. Would you like to propose a PR with a fix? |
Well, it's not like I don't want, I just wasn't completely sure about how to handle this best. My naive idea would be to define some If you think it is ok, I can just make a PR, though. To be honest, this is my first time doing a bug report, so I might not be completely familiar with the usual protocol. |
We typically set it to |
I see. I like that much more than my idea, since that doesn't require introducing some additional variable. More importantly, after analysing the code more, I doubt that my idea would have even worked. Here is what happens according to my findings: Later, in myssh_statemach_act, when On I see 3 ways on how to tackle this:
I think option two is cleaner, because then conn->sock[FIRSTSOCKET] is disabled immediately after giving up its ownership of the fd. However, I just tested it and it seems to be slower than option 1 for whatever reason. There is a noticeable delay after it displays the user name. So option one seems to be better after all. If there are no objections, I will make a PR accordingly. |
sounds reasonable to me! |
libssh closes the socket in ssh_diconnect() so make sure that libcurl does not also close it. Fixes curl#8708
I did this
Hello,
I made the following simple test program to demonstrate the issue:
Now if I compile it and run "strace -e trace=open,close" on it, I get the following:
so at the end, some file descriptor seems to get closed twice.
That is probably due to the call to ssh_disconnect in lib/vssh/libssh.c, because in that function, the socket gets already closed, but then curl closes it again later, at least as far as I understand the source code.
I expected the following
The socket should not get closed twice. If another thread opens a new socket after libssh closed it and if that socket gets the same "number" as the one already closed, then curl would kill that new socket and thus mess up some things.
curl/libcurl version
curl 7.82.0-DEV (Linux) libcurl/7.82.0-DEV OpenSSL/1.1.1 zlib/1.2.11 libssh/0.9.6/openssl/zlib
Release-Date: [unreleased]
Protocols: dict ftp ftps http https imap imaps ldap mqtt pop3 pop3s scp sftp smtp smtps tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM SSL UnixSockets
operating system
Linux BEAST 4.15.0-147-generic #151-Ubuntu SMP Fri Jun 18 19:21:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered: