Márk,

 

I  used to hit similar issue and I was able to identify the cause of it in my 
code and fix it. In my case the issue was that I was getting the inputStream 
too late in the process of setting up the ssh command. I was doing something 
like this:

 

            Channel channel = jsch.getSession(p_userName, p_host, 
PORT).openChannel("exec");

            ((ChannelExec)channel).setCommand(p_cmd);

            channel.connect();

            chanIn = channel.getInputStream();

 

So my channel.getInputStream() is called too late (after channel.connect() ) 
and by the time I get the input stream my transmission may already be over. In 
this case the input stream returned will never be closed and if you try to read 
it you will hang indefinitely.

The same aplies to channel.getExtInputStream().

 

So in my case I rearranged my code like below and the hanging went away.

 

             Channel channel = jsch.getSession(p_userName, p_host, 
PORT).openChannel("exec");

            ((ChannelExec)channel).setCommand(p_cmd);

            chanIn = channel.getInputStream();

            channel.connect();

 

 

Jacek Baranski

 

 

 

 

________________________________

From: Szabó Márk [mailto:[email protected]] 
Sent: Tuesday, August 10, 2010 4:57 AM
To: [email protected]
Subject: [JSch-users] Jsch 1.42 hangs

 

Hi all!

 

I actively use Jsch in one of our projects. However it frequently hangs, when I 
run commands through ssh. Could you help me with this problem?  I run only 
simple commands like "df -k" or "uptime", so nothing that can stuck in the 
background. (http://www.openssh.org/faq.html#3.10) At the beginning of the 
impelementation phase I saw only a few threads that stucked because this issue, 
but now it appears constantly, which exhausts resources eventually. (thus 
crashing the application...) 

 

Our system's configuration:

 

Linux used: Red Hat Enterprise Linux AS release 4 (Nahant Update 8)
OpenSSH version: openssh-3.9p1-11.el4_7
Jsch version: 1.42 (I also tried it with older releases without success.)

 

An example stacktrace:

 

Name: 10.107.40.22
State: TIMED_WAITING on com.jcraft.jsch.channel$mypipedinputstr...@1352ae2
Total blocked: 2  Total waited: 7,283

Stack trace: 
java.lang.Object.wait(Native Method)
java.io.PipedInputStream.read(PipedInputStream.java:260)
java.io.PipedInputStream.read(PipedInputStream.java:305)
sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:411)
sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:453)
sun.nio.cs.StreamDecoder.read(StreamDecoder.java:183)
java.io.InputStreamReader.read(InputStreamReader.java:167)
java.io.BufferedReader.fill(BufferedReader.java:136)
java.io.BufferedReader.readLine(BufferedReader.java:299)
java.io.BufferedReader.readLine(BufferedReader.java:362)

...

 

This thread never exits. I also tried to call Session.disconnect() to close the 
underlaying socket, but it did not work. Please help to identify the core 
problem. Thanks for your help in advance.

 

Mark Szabo 

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
JSch-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jsch-users

Reply via email to