--- jsch-0.1.53/src/main/java/com/jcraft/jsch/Session.java 2015-06-04 14:27:28.723280674 +0000 +++ jsch-0.1.54/src/main/java/com/jcraft/jsch/Session.java 2016-06-22 17:58:31.740450819 +0000 @@ -339,9 +339,16 @@ } } - try{ checkHost(host, port, kex); } + try{ + long tmp=System.currentTimeMillis(); + in_prompt = true; + checkHost(host, port, kex); + in_prompt = false; + kex_start_time+=(System.currentTimeMillis()-tmp); + } catch(JSchException ee){ in_kex=false; + in_prompt = false; throw ee; } @@ -603,6 +610,7 @@ } private volatile boolean in_kex=false; + private volatile boolean in_prompt=false; public void rekey() throws Exception { send_kexinit(); } @@ -1247,7 +1255,7 @@ while(true){ if(in_kex){ if(t>0L && (System.currentTimeMillis()-kex_start_time)>t){ - throw new JSchException("timeout in wating for rekeying process."); + throw new JSchException("timeout in waiting for rekeying process."); } try{Thread.sleep(10);} catch(java.lang.InterruptedException e){}; @@ -1339,8 +1347,11 @@ // System.err.println("in_kex="+in_kex+" "+(packet.buffer.getCommand())); long t = getTimeout(); while(in_kex){ - if(t>0L && (System.currentTimeMillis()-kex_start_time)>t){ - throw new JSchException("timeout in wating for rekeying process."); + if(t>0L && + (System.currentTimeMillis()-kex_start_time)>t && + !in_prompt + ){ + throw new JSchException("timeout in waiting for rekeying process."); } byte command=packet.buffer.getCommand(); //System.err.println("command: "+command);