When the goroutines used in the library are schedule unfavorably, Stdout will be set after starting the command. However, in the absence of a user provided pipe, the crypto/ssh library itself sets Stdout to ioutil.Discard, triggering the error that we want to set Stdout again, which is not possible.
The proposed PR solves this issue by creating the pipe outside a goroutine which ensures that no race condition exists between running the command and creating the stdout pipe.
Summary from PR:
When the goroutines used in the library are schedule unfavorably,
Stdout
will be set after starting the command. However, in the absence of a user provided pipe, thecrypto/ssh
library itself setsStdout
toioutil.Discard
, triggering the error that we want to setStdout
again, which is not possible.The proposed PR solves this issue by creating the pipe outside a goroutine which ensures that no race condition exists between running the command and creating the stdout pipe.