Skip to content

Commit 92b802a

Browse files
committed
Fix race condition in ssh-exec function when command finishes before we enter with-channel-connection
1 parent c58b4ee commit 92b802a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/clj_ssh/ssh.clj

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,16 +686,15 @@ config options."
686686
{:channel exec
687687
:out-stream out-inputstream
688688
:err-stream err-inputstream}
689-
(with-channel-connection exec
690-
(while (connected-channel? exec)
691-
(Thread/sleep 100))
692-
{:exit (.getExitStatus exec)
693-
:out (if (= :bytes out)
694-
(.toByteArray ^ByteArrayOutputStream out-stream)
695-
(.toString out-stream))
696-
:err (if (= :bytes out)
697-
(.toByteArray ^ByteArrayOutputStream err-stream)
698-
(.toString err-stream))}))))
689+
(do (while (connected-channel? exec)
690+
(Thread/sleep 100))
691+
{:exit (.getExitStatus exec)
692+
:out (if (= :bytes out)
693+
(.toByteArray ^ByteArrayOutputStream out-stream)
694+
(.toString out-stream))
695+
:err (if (= :bytes out)
696+
(.toByteArray ^ByteArrayOutputStream err-stream)
697+
(.toString err-stream))}))))
699698

700699
(defn ssh
701700
"Execute commands over ssh.

0 commit comments

Comments
 (0)