Discussion:
[JSch-users] Session hang when connected with openSSH
aarthit 2014
2014-04-10 13:28:23 UTC
Permalink
Hi All,



We are using Jsch-0.1.51 for establishing SSH sessions with our product. We
face the following issue:



The shell hangs and we are not able to enter any commands or text in the
screen.



We tested the following scenarios and these are our observations:



S/No

OS/target

SSH version

SSH server stack

Result

1

Scientific Linux release 6.0

1.5

Openssh 5.3

SSH session establishment fails with the message “Invalid server’s version
string”

2

Scientific Linux release 6.4

1.5

OpenSSH 5.3

SSH session establishment fails with the message “Invalid server’s version
string”

3

Linux-CentOS release 5.5

2.0

OpenSSH 4.3

Authentication succeeds and session gets established. The SSH shell prompt
is also received.

The session freezes there and doesn’t work.

4

Scientific Linux 6.0

2.0

Libssh 0.6.1

Authentication succeeds and the session is established the shell prompt is
also received but the session freezes.



For the above 1st 3 cases The establishment of the SSH session is not
consistent ,out of 10 trials we could see only twice the session is getting
established all the other attempts resulted in a failure.



The 4th case did not give us a successful session In any of the instances.

In the 1st two cases we changed the version to 2 and checked and in that we
see the result that session gets established but freezes.



This problem of session hang is consistent when the client is run from a
windows XP machine running with java version like

java version "1.6.0_20" . java version "1.6.0_01" .



When run from a windows 7 PC with java version "1.6.0_22" we see out of 10
times we see 2 times the session gets established and other times it is not
getting established.





Kindly let us know , why do we see the discrepancy in establishing the
sessions. And most of the times we are not seeing a successful shell. Do we
have to change any settings in the jsch config file. Or any other
modifications has to be done. Kindly let us know if any solution is
available for this and the reason for the above behavior





Thanks

Aarthi
aarthit 2014
2014-05-20 05:15:33 UTC
Permalink
Hi All,

we did further analysis and the findings are given below.

The issue is narrowed down to a read function in ChannelSession.java file.
public void run(){
Buffer buf=new Buffer((rmpsize));


while(isConnected() &&
thread!=null &&
io!=null &&
io.in!=null){
i=io.in.read(buf.buffer,
14,
buf.buffer.length-14
-Session.buffer_margin);

The third parameter to the read() gives the maximum number of bytes that
should be read. This varies based on the ssh servers we use For OpenSSH
server and libSSH server the values were 32670 and 34902 respectively. The
session hung for both these servers. Hard coding this third parameter to
26608 led to successful sessions with OpenSsh and LibSsh. Values beyond
26608 when used for the 3rd parameter led to session hang. This seems to be
the problem with java’s read API for Buffer class.

The third parameter for the read() is derived from the “rmpsize” which is
Remote max packet size which is received from the SSH server.

SSH RFC 4253 section 6.1 states that
“6.1. Maximum Packet Length

All implementations MUST be able to process packets with an
uncompressed payload length of 32768 bytes or less and a total packet
size of 35000 bytes or less (including 'packet_length',
'padding_length', 'payload', 'random padding', and 'mac'). The
maximum of 35000 bytes is an arbitrarily chosen value that is larger
than the uncompressed length noted above.”

So the values 32768 and 35000 for max packet size is valid as per the RFC.
But JSch is not compliant with this.
The RFC 4254 states that
Section 5.1:
“The 'maximum packet size' specifies the
maximum size of an individual data packet that can be sent to the
sender. For example, one might want to use smaller packets for
interactive connections to get better interactive response on slow
links.”
Hence inorder to achieve this we have done the following change in code.
and this works fine.
-->diff ChannelSession.java_bkup ChannelSession.java
237c237
< Buffer buf=new Buffer(rmpsize);
---
Buffer buf=new Buffer(1000);
Kindly let us know if there are any comments on this.

Thanks
Aarthi
Hi All,
We are using Jsch-0.1.51 for establishing SSH sessions with our product.
The shell hangs and we are not able to enter any commands or text in the
screen.
S/No
OS/target
SSH version
SSH server stack
Result
1
Scientific Linux release 6.0
1.5
Openssh 5.3
SSH session establishment fails with the message “Invalid server’s version
string”
2
Scientific Linux release 6.4
1.5
OpenSSH 5.3
SSH session establishment fails with the message “Invalid server’s version
string”
3
Linux-CentOS release 5.5
2.0
OpenSSH 4.3
Authentication succeeds and session gets established. The SSH shell
prompt is also received.
The session freezes there and doesn’t work.
4
Scientific Linux 6.0
2.0
Libssh 0.6.1
Authentication succeeds and the session is established the shell prompt is
also received but the session freezes.
For the above 1st 3 cases The establishment of the SSH session is not
consistent ,out of 10 trials we could see only twice the session is getting
established all the other attempts resulted in a failure.
The 4th case did not give us a successful session In any of the instances.
In the 1st two cases we changed the version to 2 and checked and in that
we see the result that session gets established but freezes.
This problem of session hang is consistent when the client is run from a
windows XP machine running with java version like
java version "1.6.0_20" . java version "1.6.0_01" .
When run from a windows 7 PC with java version "1.6.0_22" we see out of 10
times we see 2 times the session gets established and other times it is not
getting established.
Kindly let us know , why do we see the discrepancy in establishing the
sessions. And most of the times we are not seeing a successful shell. Do we
have to change any settings in the jsch config file. Or any other
modifications has to be done. Kindly let us know if any solution is
available for this and the reason for the above behavior
Thanks
Aarthi
Atsuhiko Yamanaka
2014-05-22 05:46:06 UTC
Permalink
Hi,

+-From: aarthit 2014 <***@gmail.com> --
|_Date: Tue, 20 May 2014 10:45:33 +0530 _______
|
|The third parameter for the read() is derived from the rmpsize which is
|Remote max packet size which is received from the SSH server.

No, that size means that how long data SSH server can receive.
Have you confirmed that the program has freezed in read() method?

I guess the program has freezed in sending data to the SSH server.
I don't know the reason, but your network environment may have problems
in transferring long data, or your SSH sever may have problems
in receiving long data.


Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
aarthit 2014
2014-05-30 06:39:48 UTC
Permalink
Hi ,

Thanks for the reply, when we added debugs we saw that the code hit
the part in this read function call on reaching the read call the
session freezes.

The value rmpzize we understand that is a value that comes from the
ssh server. we confirmed this by testing with different ssh servers.
The values were
OpenSSH server 32760
libSSH server 34902

This is not specific to a particular server. when we verified in 2
different servers we saw the same issue of session hang in the read
call .
when we change the value of this rmpsize starting from 1000 to 26608
for libssh server the session was working fine. which implies that the
client is not able to handle the size received from the SSH server.
But as per the RFC that we had already quoted the size obtained from
Openssh and libssh are also valid (32760 and 34902). Even they are
valid when the Jsch does a java read call it is not handling the
rmpsize properly. we suspect the issue with the java implementation.

Kindly share your thoughts.

Thanks
Aarthi
Post by Atsuhiko Yamanaka
Hi,
|_Date: Tue, 20 May 2014 10:45:33 +0530 _______
|
|The third parameter for the read() is derived from the rmpsize which is
|Remote max packet size which is received from the SSH server.
No, that size means that how long data SSH server can receive.
Have you confirmed that the program has freezed in read() method?
I guess the program has freezed in sending data to the SSH server.
I don't know the reason, but your network environment may have problems
in transferring long data, or your SSH sever may have problems
in receiving long data.
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
aarthit 2014
2014-06-18 13:17:59 UTC
Permalink
Hi ,

We have a sample program

import java.*;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class exampleread
{
public static void main(String[] args)
{

InputStream io1 = System.in;
byte[] buf = new byte[32768];
int i = -1;

try {

* i=io1.read(buf, 0, 32768);*
String str = new String(buf);
System.out.println ("I read " + buf + "as string" + str);
}
catch (Exception e)
{
System.out.println("Excecption received" + e );
}
}
}


In this program when we change the value of the third parameter of the
read call to value greater than 26608 we get the following exception when
run in windows XP with java version 1.6.0_22


*java.io.IOException: Not enough storage is available to process this
command*

But the same program is working fine when it is run in windows 7 machine
with same JRE version even if we increase the values upto 32767.


Could you please let us know what would be the reason behind this. Is this
a limitation of the read call over the operating system used.

Thanks
Aarthi
Post by aarthit 2014
Hi ,
Thanks for the reply, when we added debugs we saw that the code hit
the part in this read function call on reaching the read call the
session freezes.
The value rmpzize we understand that is a value that comes from the
ssh server. we confirmed this by testing with different ssh servers.
The values were
OpenSSH server 32760
libSSH server 34902
This is not specific to a particular server. when we verified in 2
different servers we saw the same issue of session hang in the read
call .
when we change the value of this rmpsize starting from 1000 to 26608
for libssh server the session was working fine. which implies that the
client is not able to handle the size received from the SSH server.
But as per the RFC that we had already quoted the size obtained from
Openssh and libssh are also valid (32760 and 34902). Even they are
valid when the Jsch does a java read call it is not handling the
rmpsize properly. we suspect the issue with the java implementation.
Kindly share your thoughts.
Thanks
Aarthi
Post by Atsuhiko Yamanaka
Hi,
|_Date: Tue, 20 May 2014 10:45:33 +0530 _______
|
|The third parameter for the read() is derived from the rmpsize which
is
Post by Atsuhiko Yamanaka
|Remote max packet size which is received from the SSH server.
No, that size means that how long data SSH server can receive.
Have you confirmed that the program has freezed in read() method?
I guess the program has freezed in sending data to the SSH server.
I don't know the reason, but your network environment may have problems
in transferring long data, or your SSH sever may have problems
in receiving long data.
Sincerely,
--
Atsuhiko Yamanaka
JCraft,Inc.
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.
Tel +81-22-723-2150
Skype callto://jcraft/
Twitter: http://twitter.com/ymnk
Facebook: http://facebook.com/aymnk
Lothar Kimmeringer
2014-06-18 13:58:43 UTC
Permalink
Post by aarthit 2014
InputStream io1 = System.in;
byte[] buf = new byte[32768];
int i = -1;
try {
* _i=io1.read(buf, 0, 32768);_
*
String str = new String(buf);
System.out.println ("I read " + buf + "as string" + str);
}
catch (Exception e)
{
System.out.println("Excecption received" + e );
}
}
}
In this program when we change the value of the third parameter
of the read call to value greater than 26608 we get the following
exception when run in windows XP with java version 1.6.0_22
*
java.io.IOException: Not enough storage is available to process this command
*
But the same program is working fine when it is run in windows 7
machine with same JRE version even if we increase the values upto 32767.
The error-message comes from the operating system and has nothing to
do with Java/JSCH. See e.g.
http://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/not-enough-storage-is-available-to-process-this/9624b57d-ea4c-41fa-aae0-b52e99b69fab
That's the first Google-Hit covering that error-message. As you
can see, the error can also occur on later versions of Windows
and I've seen this kind of error on other operating systems as
well (e.g. with a JVM on a BS2000-system - don't ask ;-)

The way you read in the data is not good practice anyway and can
lead to problems on Windows 7 as well, e.g. if not all data
resides in one TCP-packet and the seconds arrives delayed. A better
approach for that e.g. is

byte[] buf = new byte[maxLength]
int read;
int offset = 0;

while (offset < buf.length && (read = io1.read(buf, offset, Math.min(4096, buf.length - offset)) != -1){
offset += read;
}


Cheers, Lothar
aarthit 2014
2014-06-19 08:55:28 UTC
Permalink
Hi Lothar ,

Thanks for your explanation. But this example program was written based on
the ChannelSession.java and shell.java programs that are present in the
jsch package, and this the way they use the read call and that is what is
causing us the issue.
So which means the way in which the channelSession.java and shell.java
program is written in jsch must also be changed.

Thanks
Aarthi
Post by aarthit 2014
Post by aarthit 2014
InputStream io1 = System.in;
byte[] buf = new byte[32768];
int i = -1;
try {
* _i=io1.read(buf, 0, 32768);_
*
String str = new String(buf);
System.out.println ("I read " + buf + "as string" + str);
}
catch (Exception e)
{
System.out.println("Excecption received" + e );
}
}
}
In this program when we change the value of the third parameter
of the read call to value greater than 26608 we get the following
exception when run in windows XP with java version 1.6.0_22
*
java.io.IOException: Not enough storage is available to process this
command
Post by aarthit 2014
*
But the same program is working fine when it is run in windows 7
machine with same JRE version even if we increase the values upto 32767.
The error-message comes from the operating system and has nothing to
do with Java/JSCH. See e.g.
http://answers.microsoft.com/en-us/windows/forum/windows_7-hardware/not-enough-storage-is-available-to-process-this/9624b57d-ea4c-41fa-aae0-b52e99b69fab
That's the first Google-Hit covering that error-message. As you
can see, the error can also occur on later versions of Windows
and I've seen this kind of error on other operating systems as
well (e.g. with a JVM on a BS2000-system - don't ask ;-)
The way you read in the data is not good practice anyway and can
lead to problems on Windows 7 as well, e.g. if not all data
resides in one TCP-packet and the seconds arrives delayed. A better
approach for that e.g. is
byte[] buf = new byte[maxLength]
int read;
int offset = 0;
while (offset < buf.length && (read = io1.read(buf, offset, Math.min(4096,
buf.length - offset)) != -1){
offset += read;
}
Cheers, Lothar
------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
JSch-users mailing list
https://lists.sourceforge.net/lists/listinfo/jsch-users
Loading...