[JSch-users] Using sessions pool to reuse session and multiple channels.
Status: Alpha
Brought to you by:
ymnk
|
From: Alexander K. <al...@tm...> - 2005-02-17 02:49:20
|
Hello All,
I'm using jsch library in JavaSVN (pure java subversion client library).
Users reported that svn+ssh connectivity is slow, slower then with =
native
ssh client, and so I decided to establish sessions pools as I read in =
this
newsgroup.=20
I own two servers with different versions of openssh running. One sever =
is
pretty responsive and other is VPS that is very slow :) I implemented
sessions pool more or less the same way as in Eclipse cvsssh2 plugin - I
reuse session object and create channel objects. My code looks like =
this:
private Channel myChannel;
public void open(SVNRepositoryLocation location, ISVNSSHCredentials =
creds) {
// not the real code, but quite understanble I hope=20
Session session =3D SessionsPool.get(location, creds); // session is
created or reused.
try {
myChannel =3D (ChannelExec) session.openChannel("exec");
String command =3D "svnserve --tunnel";
myChannel.setCommand(command);
=20
myOutputStream =3D myChannel.getOutputStream();
myInputStream =3D myChannel.getInputStream();
myChannel.connect();
}=20
// some more code.
}
public void close() {
myChannel.disconnect();
myChannel =3D null;
}
The problem I always have with slow server and sometimes with the fast =
one
is that session is not reused and, sometimes, remote command execution
results are not received and session is closed by timeout. I debuged =
jsch
(0.1.20) and as far as I understood the following happens:
1. session is started and starts reading data (from server and from =
channel
as soon as they are created, as far as I understood)
2. channel (1) is started.
3. channel (1) receives data from server and I call "close" method in =
the
above code (Channel.disconnect()).=20
(3.1. Immedeatly after I open new channel with the same session.)
4. channel (1) sends server "CHANNEL_CLOSED", removes itself from the =
pool
of channels, all this is done in non-channel thread, so it continues to =
read
data from server.
5. channel (1) receives EOF from server and sends EOF to server (or =
session,
this I do not fully understand). (Channel.eof())
6. server responds with "eof from unknown channel", this is read by =
session,
session disconnects. (Session.read())
Sometimes session hangs in "session.read()" method after first channel =
is
closed and then disconnects by timeout. Data received by the new channel =
is
not read in this case at all.
I may imagine, that with the fast connection session doesn't receive =
error
from the server because it starts listen to the new channel as soon as =
it is
created or may be points 4,5,6 goes in slightly different order. The
solution I found so far is changing Channel.eof() method the following =
way:
void eof(){
if (eof_local || close) {
return;
}
/* previous version.
if(eof_local) {
return;
}*/
eof_local=3Dtrue;
// ... more code
}
My question is - are my assumptions correct and do I really found a bug =
in
jsch or there is something not correct in the way I'm using channels and
sessions?
Thanks!
PS. OpenSSH version on the "slow" server is 3.6.1p2.=20
Alexander Kitaev,
TMate Software,
http://tmatesoft.com/
|