Repository navigation
Closed
Labels
Description
Describe the bug
even with libssh2_session_set_blocking(session, 0) set, libssh2_session_handshake often hangs for me... and then after a minute or more fails with LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE. but the keys are correct and do work sometimes. they either work instantly or we hang for a while. so something is definitely wrong.
To Reproduce
this is the code i'm using.. nothing special...
bool connect(void)
{
libssh2_session_set_blocking(session, 1);
createTCPSocket(AF_INET);
setIPv4FromString(host, 22);
int rc = SocketBase::connect();
if (rc != 0)
{
fprintf(stderr, "Failure establishing TCP connection: %d\n", rc);
goto shutdown;
}
ipc_printf("SSHClient::connect: before calling libssh2_session_handshake\n");
rc = libssh2_session_handshake(session, fd);
if (rc != LIBSSH2_ERROR_NONE && rc != LIBSSH2_ERROR_EAGAIN)
{
fprintf(stderr, "libssh2_session_handshake failed\n");
printErrorString(rc);
goto shutdown;
}
ipc_printf("SSHClient::connect: before calling libssh2_userauth_publickey_fromfile\n");
rc = libssh2_userauth_publickey_fromfile(session, user.c_str(), pubkey_path.c_str(), privkey_path.c_str(), NULL);
if (rc != LIBSSH2_ERROR_NONE && rc != LIBSSH2_ERROR_EAGAIN)
{
fprintf(stderr, "libssh2_userauth_publickey_fromfile failed\n");
printErrorString(rc);
goto shutdown;
}
return true;
shutdown:
ipc_printf("SSHClient::connect: checkpoint shutdown\n");
if (session)
{
libssh2_session_disconnect(session, "Normal Shutdown");
libssh2_session_free(session);
}
return false;
}Expected behavior
expect it to quickly complete as it does sometimes
Version:
- OS and version: Linux (Clear Linux 6.8.4-1422)
- libssh2 version: 1.11.0
- crypto backend and version: OpenSSL 3
Additional context
Activity
[-]libssh2_session_handshake hangs[/-][+]`libssh2_session_handshake()` hangs[/+][-]`libssh2_session_handshake()` hangs[/-][+]libssh2_session_handshake() hangs[/+]victorstewart commentedon Apr 19, 2024
here's some log with all debug besides LIBSSH2_TRACE_TRANS enabled, plus the packets filtered by the IP address of the target SSH server printed in order from custom eBPF observer programs i injected into the ingress and egress points of the ethernet device.
victorstewart commentedon Apr 19, 2024
i tired downgrading to 1.10.0 and this error never appears, but now i have different errors with
libssh2_sftp_writethat i didn't see in 1.11.0 so i assume they're fixed. so kind of trapped here.victorstewart commentedon Apr 19, 2024
if i keep just SIGINT-ing the program when it blocks on this error, then restart it, eventually it runs to completion.
daniel-heater-imprivata commentedon Sep 13, 2024
@victorstewart It might be a lack of entropy. See: https://libssh2.org/mail/libssh2-devel-archive-2021-06/0001.shtml
You could try a tool like
havegedto introduce some entropy and see if that solves your issue.willco007 commentedon Nov 21, 2024
What is the server and version you're connecting to?
vszakats commentedon Jun 30, 2026
It may be worth testing with 1.11.1 or the latest master to see if the
issue replicates, also latest OpenSSL 3.
Closing due to inactivity. Also ref #1370 that describes a similar issue.