Menu

#25 ssh client hangs when remote server doesn't reply during kex

Unstable
open
nobody
J2SSH (18)
5
2006-12-12
2006-12-12
cpo
No

i had a problem with an equipment randomly not responding during the key exchange. as we're in a blocking read, it causes the client to hang on this read in TransportProtocolInputStream.

The provided patch replaces the BufferedInputStream with an home made TimedBufferedInputStream which stops after a 60s default timeout.

another way to fix it is replacing the following code :
try {
read = in.read(buffered, endpos, (buffered.length - endpos));
}
catch (InterruptedIOException ex) {
// We have an interrupted io; inform the event handler

with :
try {
final int waitms = 60000;
int ms = 0;
while (in.available()==0) {
try {
Thread.sleep(10);
ms += 10;
} catch (InterruptedException e) {
break;
}
if (ms >= waitms) {
throw new IOException("read timed out");
}
}
read = in.read(buffered, endpos, (buffered.length - endpos));
}
catch (InterruptedIOException ex) {
// We have an interrupted io; inform the event handler

thoses fixes have been successfully tested on the equipment that causes the problem.

A possible evolution of this patch would be the configuration of the timeout from the SshClient object.

Discussion

  • cpo

    cpo - 2006-12-12

    added a timeout in TransportProtocolInputStream

     
  • cpo

    cpo - 2006-12-12

    Logged In: YES
    user_id=1666492
    Originator: YES

    just forgot to mention that i used the latest cvs version

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.