Merge pull request #8335 from sakshamkhanna/bugfix/sakshamkhanna/ssh_runner_race_condition

added mutex lock over teePrefix()
pull/8385/head
Medya Ghazizadeh 2020-06-04 14:00:08 -07:00 committed by GitHub
commit 21b7cebaf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import (
"os/exec"
"strconv"
"strings"
"sync"
"time"
"github.com/pkg/errors"
@ -37,6 +38,9 @@ var (
// OutPrefix notes output
OutPrefix = "> "
// Mutex protects teePrefix from writing to same log buffer parallelly
logMutex = &sync.Mutex{}
)
// RunResult holds the results of a Runner
@ -88,6 +92,9 @@ func (rr RunResult) Output() string {
// teePrefix copies bytes from a reader to writer, logging each new line.
func teePrefix(prefix string, r io.Reader, w io.Writer, logger func(format string, args ...interface{})) error {
logMutex.Lock()
defer logMutex.Unlock()
scanner := bufio.NewScanner(r)
scanner.Split(bufio.ScanBytes)
var line bytes.Buffer