bramvdbogaerde / go-scp

Simple Golang scp client
Mozilla Public License 2.0
424 stars 89 forks source link

scp file raise "Stdout already set" error #37

Closed qcha0 closed 3 years ago

bramvdbogaerde commented 3 years ago

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, 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.

bramvdbogaerde commented 3 years ago

Fixed by PR