Skip to content

Commit 9d45d42

Browse files
committed
jupiterbrain: copy stdout/stderr to log writer via pipe
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.
1 parent 2cab2ea commit 9d45d42

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/github.com/travis-ci/worker/backend/jupiterbrain.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,18 @@ func (i *jupiterBrainInstance) RunScript(ctx context.Context, output io.Writer)
401401
return &RunResult{Completed: false}, err
402402
}
403403

404-
session.Stdout = output
405-
session.Stderr = output
404+
stdoutPipe, err := session.StdoutPipe()
405+
if err != nil {
406+
return &RunResult{Completed: false}, err
407+
}
408+
409+
stderrPipe, err := session.StderrPipe()
410+
if err != nil {
411+
return &RunResult{Completed: false}, err
412+
}
413+
414+
go io.Copy(output, stdoutPipe)
415+
go io.Copy(output, stderrPipe)
406416

407417
errChan := make(chan error, 1)
408418

0 commit comments

Comments
 (0)