Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't call into
CombinedOutput
for subprocesses
The documentation for `exec.Cmd` says this about `Stdout` and `Stderr`: // If either is an *os.File, the corresponding output from the process // is connected directly to that file. // // Otherwise, during the execution of the command a separate goroutine // reads from the process over a pipe and delivers that data to the // corresponding Writer. In this case, Wait does not complete until the // goroutine reaches EOF or encounters an error. When calling `CombinedOutput()`, `Stdout` and `Stderr` are `bytes.Buffer`s and are therefore not `*os.File`s so they fall into this second group. This resulted in a race condition where cancelling the context when `maxtime` has passed could cause `CombinedOutput()` to hang indefinitely waiting for the (finished) subprocess to "finish" writing to its pipes. This has been reported as an issue several times. The tracking issue is golang/go#23019 which itself links to several other issues that are duplicates. To work around the issue we simply force the other behavior by creating a temporary `*os.File` for the combined `stdout` and `stderr`.
- Loading branch information