diff --git a/compute/src/main/java/org/jclouds/ssh/SshClient.java b/compute/src/main/java/org/jclouds/ssh/SshClient.java index f1cce775b4..f152aff37a 100644 --- a/compute/src/main/java/org/jclouds/ssh/SshClient.java +++ b/compute/src/main/java/org/jclouds/ssh/SshClient.java @@ -48,9 +48,7 @@ public interface SshClient { ExecResponse exec(String command); /** - * Execute a process and allow the user to interact with it. Note that this will allow the - * session to exist indefinitely, and its connection is not closed when {@link #disconnect()} is - * called. + * Execute a process and allow the user to interact with it. * * @param command * command line to invoke diff --git a/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java b/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java index b1f60b5e78..8dd6791df8 100644 --- a/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java +++ b/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java @@ -500,8 +500,8 @@ public class SshjSshClient implements SshClient { class ExecChannelConnection implements Connection { private final String command; - private SessionChannel session; private Command output; + private Connection connection; ExecChannelConnection(String command) { this.command = checkNotNull(command, "command"); @@ -510,13 +510,19 @@ public class SshjSshClient implements SshClient { @Override public void clear() { Closeables2.closeQuietly(output); - Closeables2.closeQuietly(session); + try { + if (connection != null) { + connection.clear(); + } + } catch (Throwable e) { + Throwables.propagate(e); + } } @Override public ExecChannel create() throws Exception { - session = SessionChannel.class.cast(acquire(noPTYConnection())); - output = session.exec(command); + connection = noPTYConnection(); + output = SessionChannel.class.cast(acquire(connection)).exec(command); return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(), new Supplier() {