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:
Luca Milanesio
2016-12-30 11:33:51 +00:00
parent e1d12494d9
commit d4bef1bad6

View File

@@ -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");