Hi,
I seem to be having a similar issue as :https://www.libssh2.org/mail/libssh2-devel-archive-2011-12/0021.shtml
In my case the application is not crashing, but that specific thread just hangs forever.
After the libssh2_sftp_opendir call fails, should I perform any check before trying to close the connection?
Should I be calling connection_status method from https://www.libssh2.org/mail/libssh2-devel-archive-2011-12/att-0021/sftp.c and just skip closing the connection if the connection is already lost? Is there anything else I could do to avoid the thread hanging?
libssh2 version: 1.7.0
Code snippet:
sftpHandle_ = libssh2_sftp_opendir(sftpSession_, remoteWorkingDirectory_.c_str());
if(!sftpHandle_) {
std::cout<< "Unable to open dir with SFTP : "
<< remoteWorkingDirectory_
<< std::endl;
std::cout << "Shutting down SFTP..."<< std::endl;
if (sftpSession_ != NULL )
{
std::cout << "Shutdown SFTP connection"<< std::endl;
libssh2_sftp_shutdown(sftpSession_);
std::cout << "Done shutting down SFTP connection"<< std::endl;
sftpSession_ = NULL;
std::cout << "Done resetting SFTP connection"<< std::endl;
}
std::cout << "Done shutting down SFTP"<< std::endl;
std::cout << "Shutting down SSH..."<< std::endl;
if (!sshSession_)
{
std::cout << "Done shutting down SSH connection , ssh session was NULL"<< std::endl;
return;
}
std::cout << "Disconnecting SSH connection..."<< std::endl;
libssh2_session_disconnect(sshSession_, "Normal Shutdown");
std::cout << "Free SSH session..."<< std::endl;
libssh2_session_free(sshSession_);
}
Example output:
2020-08-24 22:49:28.512 [T13]:Unable to open dir with SFTP : my_test_dir
2020-08-24 22:49:28.512 [T13]:Shutting down SFTP...
2020-08-24 22:49:28.512 [T13]:Shutdown SFTP connection
2020-08-24 22:49:28.512 [T13]:Done shutting down SFTP connection
2020-08-24 22:49:28.512 [T13]:Done resetting SFTP connection
2020-08-24 22:49:28.512 [T13]:Done shutting down SFTP
2020-08-24 22:49:28.512 [T13]:Shutting down SSH...
2020-08-24 22:49:28.512 [T13]:Disconnecting SSH connection...
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2020-08-31