From 79d58734453394aa2fc3c066ffd04575ad698aa4 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 10 Mar 2024 17:00:02 -0400 Subject: [PATCH] engine: resources: Also look at stderr We might have an executing program which prints on stderr which we were effectively ignoring. Read from that too. --- engine/resources/exec.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/resources/exec.go b/engine/resources/exec.go index 1d94b63e..5d9b5ac4 100644 --- a/engine/resources/exec.go +++ b/engine/resources/exec.go @@ -34,6 +34,7 @@ import ( "bytes" "context" "fmt" + "io" "os/exec" "os/user" "sort" @@ -905,10 +906,17 @@ type cmdOutput struct { // Cancelling the context merely unblocks the sending on the output channel, it // does not Kill the cmd process. For that you must do it yourself elsewhere. func (obj *ExecRes) cmdOutputRunner(ctx context.Context, cmd *exec.Cmd) (chan *cmdOutput, error) { - cmdReader, err := cmd.StdoutPipe() + stdoutReader, err := cmd.StdoutPipe() if err != nil { return nil, errwrap.Wrapf(err, "error creating StdoutPipe for Cmd") } + stderrReader, err := cmd.StderrPipe() + if err != nil { + return nil, errwrap.Wrapf(err, "error creating StderrPipe for Cmd") + } + // XXX: Can io.MultiReader when one of these is still open? Is there an + // issue or race here about calling cmd.Wait() if only one of them dies? + cmdReader := io.MultiReader(stdoutReader, stderrReader) scanner := bufio.NewScanner(cmdReader) if err := cmd.Start(); err != nil { return nil, errwrap.Wrapf(err, "error starting Cmd")