Hi,
+-From: "B. Scott Smith" <[email protected]> --
|_Date: Fri, 13 Aug 2010 11:40:34 -0400 ___________
|
|I have found a timing issue with reverse port forwarding
|(session.setPortForwardingR). This is affecting my application when it
|is running on the same physical box as the SSH server. My application
|sets up a series of remote forwards, and I noticed that calls to
|session.setPortForwardingR() take a very long time (exactly 10 seconds
|to be precise). This is because the reply from the SSH server is being
|received before the sending thread is ready (sleeping). So, the thread
|interrupt never occurs, and the sending thread sleeps for the full 10
|seconds.
...
Sorry for my delay.
How about the following change?
It will not sleep so long time even if at the worst case.
--- jsch-0.1.43/src/com/jcraft/jsch/Session.java 2010-08-24
08:30:21.000000000 +0000
+++ jsch-0.1.44/src/com/jcraft/jsch/Session.java 2010-09-22
08:32:42.000000000 +0000
@@ -1673,6 +1673,8 @@
String address_to_bind=ChannelForwardedTCPIP.normalize(bind_address);
+ grr.setThread(Thread.currentThread());
+
try{
// byte SSH_MSG_GLOBAL_REQUEST 80
// string "tcpip-forward"
@@ -1682,25 +1684,29 @@
packet.reset();
buf.putByte((byte) SSH_MSG_GLOBAL_REQUEST);
buf.putString(Util.str2byte("tcpip-forward"));
-// buf.putByte((byte)0);
buf.putByte((byte)1);
buf.putString(Util.str2byte(address_to_bind));
buf.putInt(rport);
write(packet);
}
catch(Exception e){
+ grr.setThread(null);
if(e instanceof Throwable)
throw new JSchException(e.toString(), (Throwable)e);
throw new JSchException(e.toString());
}
- grr.setThread(Thread.currentThread());
- try{ Thread.sleep(10000);}
- catch(Exception e){
+ int count = 0;
+ int reply = grr.getReply();
+ while(count < 10 && reply == -1){
+ try{ Thread.sleep(1000); }
+ catch(Exception e){
+ }
+ count++;
+ reply = grr.getReply();
}
- int reply=grr.getReply();
grr.setThread(null);
- if(reply==0){
+ if(reply != 1){
throw new JSchException("remote port forwarding failed for listen port
"+rport);
}
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users