Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid a goroutine leak by ensuring pipes closed
The func runCmd uses io.Pipe for both stderr and stdout of the command it runs, so writes on either can be echoed to the log as they happen; and two goroutines for doing that echoing. In process dumps, it's apparent that these goroutines leak -- they are blocked on Scan, which is presumably waiting for an EOF. This commit replaces the explicit pipe plumbing with `Command.StdoutPipe()` and `Command.StderrPipe()`. The Command machinery knows to close the readers when the process has finished writing, so Scan no longer blocks indefinitely. It's also not necessary to start _two_ new goroutines, since we already have one -- that in which we're running. Signed-off-by: Michael Bridgen <[email protected]>
- Loading branch information