Fix SshSession consumption deadlock in integration tests
JSch reads the input and error streams eagerly when they are returned from the Channel. As a result the Scanner of the error stream could be already trying to read from a Stream in EOF, which unfortunately was leading to a deadlock because of a bad implementation in the JSch code using PipedInputStream. Consume the error stream immediately and get the data out before reaching EOF, so that the deadlock can be avoided. Change-Id: I60b6e5156ec9f649fbe3b7581cde974c8c233fbc
This commit is contained in:
@@ -49,9 +49,10 @@ public class SshSession {
|
||||
channel.setCommand(command);
|
||||
channel.setInputStream(opt);
|
||||
InputStream in = channel.getInputStream();
|
||||
InputStream err = channel.getErrStream();
|
||||
channel.connect();
|
||||
|
||||
Scanner s = new Scanner(channel.getErrStream()).useDelimiter("\\A");
|
||||
Scanner s = new Scanner(err).useDelimiter("\\A");
|
||||
error = s.hasNext() ? s.next() : null;
|
||||
|
||||
s = new Scanner(in).useDelimiter("\\A");
|
||||
|
Reference in New Issue
Block a user