Open rasantel opened 7 months ago
Please disregard the mention above from PR https://github.com/hierynomus/sshj/pull/911. I referenced the wrong issue there (I meant issue #910, not #909).
By the way, I'm looking into the code to see if I can propose a fix and raise a PR for #909.
Occasionally, my sshj client hits a timeout exception almost as soon as the main thread starts waiting for the key exchange to complete, even though the timeout has not been reached.
Based on the logs and code, this can happen during the following sequence of events between the main thread and the reader thread:
This is a race condition. What happens under the covers is:
SSH_MSG_KEXINIT
from the server before the main thread has a chance to initiate that exchange.done.clear()
inKeyExchanger.startKex
, the main thread also callsKeyExchanger.startKex
, skips the key exchange initiation (because it's already ongoing) and callsdone.await
with a timeout to wait for the exchange to complete.done.await
callsPromise.retrieve
which callsPromise.tryRetrieve
, which waits for the associated condition viacond.await
.done.clear()
, which delivers a value ofnull
to thedone
promise.cond.await
to wake up the main thread, andPromise.tryRetrieve
returns thisnull
value.Promise.retrieve
throws a timeout exception because the retrieved value isnull
, even though there wasn't a timeout.