Merge pull request #8335 from sakshamkhanna/bugfix/sakshamkhanna/ssh_runner_race_condition
added mutex lock over teePrefix()pull/8385/head
commit
21b7cebaf9
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue