diff --git a/src/main/java/net/schmizz/sshj/connection/ConnectionImpl.java b/src/main/java/net/schmizz/sshj/connection/ConnectionImpl.java index 7716ce65..c942757b 100644 --- a/src/main/java/net/schmizz/sshj/connection/ConnectionImpl.java +++ b/src/main/java/net/schmizz/sshj/connection/ConnectionImpl.java @@ -216,13 +216,15 @@ public class ConnectionImpl throws ConnectionException { synchronized (globalReqPromises) { Promise gr = globalReqPromises.poll(); - if (gr == null) + if (gr == null) { throw new ConnectionException(DisconnectReason.PROTOCOL_ERROR, - "Got a global request response when none was requested"); - else if (response == null) + "Got a global request response when none was requested"); + } else if (response == null) { gr.deliverError(new ConnectionException("Global request [" + gr + "] failed")); - else - gr.deliver(response); + } else { + // To prevent a race condition, copy the packet before delivering, as it will be handled in a different thread. + gr.deliver(new SSHPacket(response)); + } } } @@ -278,4 +280,4 @@ public class ConnectionImpl return keepAlive; } -} \ No newline at end of file +} diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 00000000..ac8ace3c --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,16 @@ + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%.-20thread] %-5level %logger{36} - %msg%n + + + + + + + + + + +