This is an automated email from the ASF dual-hosted git repository.

twolf pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git


The following commit(s) were added to refs/heads/master by this push:
     new 62970af  Fix ScpTest hanging sometimes
62970af is described below

commit 62970afa5db70ef9308eecfedd4dfb8ddf00930a
Author: Thomas Wolf <tw...@apache.org>
AuthorDate: Thu Jul 8 18:48:51 2021 +0200

    Fix ScpTest hanging sometimes
    
    ScpTests with JSch would hang sometimes, waiting in vain for an ACK.
    With JSch, one has to set up the input/output streams for a ChannelExec
    *before* connecting, otherwise it's apparently possible that one misses
    some data on the input.
---
 .../src/test/java/org/apache/sshd/scp/client/ScpTest.java    | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java 
b/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
index 7f4f2e4..3c03526 100644
--- a/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
+++ b/sshd-scp/src/test/java/org/apache/sshd/scp/client/ScpTest.java
@@ -938,11 +938,11 @@ public class ScpTest extends AbstractScpTestSupport {
     protected String readFile(com.jcraft.jsch.Session session, String path, 
Path target) throws Exception {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         c.setCommand("scp -f " + path);
-        c.connect();
 
         String fileName = Objects.toString(target.getFileName(), null);
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
 
             os.write(0);
             os.flush();
@@ -975,10 +975,10 @@ public class ScpTest extends AbstractScpTestSupport {
     protected String readDir(com.jcraft.jsch.Session session, String path, 
Path target) throws Exception {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         c.setCommand("scp -r -f " + path);
-        c.connect();
 
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
             ScpAckInfo.sendOk(os, StandardCharsets.UTF_8);
 
             String header = ScpIoUtils.readLine(is, StandardCharsets.UTF_8, 
false);
@@ -1017,10 +1017,10 @@ public class ScpTest extends AbstractScpTestSupport {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         String command = "scp -f " + path;
         c.setCommand(command);
-        c.connect();
 
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
 
             ScpAckInfo.sendOk(os, StandardCharsets.UTF_8);
             assertEquals("Mismatched response for command: " + command, 
ScpAckInfo.ERROR, is.read());
@@ -1033,10 +1033,10 @@ public class ScpTest extends AbstractScpTestSupport {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         String command = "scp -t " + path;
         c.setCommand(command);
-        c.connect();
 
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
 
             assertAckReceived(is, command);
 
@@ -1072,10 +1072,10 @@ public class ScpTest extends AbstractScpTestSupport {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         String command = "scp -t " + path;
         c.setCommand(command);
-        c.connect();
 
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
 
             assertAckReceived(is, command);
 
@@ -1092,10 +1092,10 @@ public class ScpTest extends AbstractScpTestSupport {
         ChannelExec c = (ChannelExec) 
session.openChannel(Channel.CHANNEL_EXEC);
         String command = "scp -t -r " + path;
         c.setCommand(command);
-        c.connect();
 
         try (OutputStream os = c.getOutputStream();
              InputStream is = c.getInputStream()) {
+            c.connect();
 
             assertAckReceived(is, command);
             assertAckReceived(os, is, "D0755 0 " + dirName);

Reply via email to