Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
x/crypto/ssh: data race if session.Stdout and Stderr are the same writer #5582
https://golang.org/cl/9711043/ identified that the ssh package does not handle the case where the Stdout and Stderr point to the same writer, as in the case of the CombinedOutput() helper function. This was worker around by introducing a blocking wrapper, however the proper solution is to handle this common case the way os/exec handles it.
I had a quick look this afternoon and although they share the same API, os/exec an ssh share a different underlying implementation. When os/exec detects that stdout and stderr are the same writer, it passes the pipe representing stdout to the underlying exec as stderr. ssh is a little different, we have two handlers for stdout and strerr, this goes all the way up to the channel level, and they are established quite early. The easiest thing will probably be to keep kr's singleWriter but make it internal.
Apparently there's a data race when stdout and stderr is the same writer: golang/go#5582. We're gonna attempt to work around it by letting the library generate pipes for both stdout and stderr and then using io.Copy to copy all of the data back to the log writer.