When connecting to a remote host using jsch version 0.1.51 we occasionally run into the following exception when calling Channel.connect()
on a ChannelExec
.
com.jcraft.jsch.JSchException: channel is not opened.
at com.jcraft.jsch.Channel.sendChannelOpen(Channel.java:765)
at com.jcraft.jsch.Channel.connect(Channel.java:151)
at com.jcraft.jsch.Channel.connect(Channel.java:145)
The code we use after the session has been created is:
ChannelExec channel = (ChannelExec) session.openChannel("exec");
channel.setCommand("echo hello");
channel.connect(); // Error here
The Channel.connect()
call usually returns in under 100 ms, but when this error ocurrs the call hangs for more than 20 seconds before throwing the exception.