Skip to content

Commit

Permalink
prevent possible data race in supervisor stdout/file logger (#404)
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
  • Loading branch information
VladoLavor authored and ondrej-fabry committed Aug 21, 2019
1 parent 19cae2a commit 0adde62
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions exec/supervisor/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ import (
"bufio"
"log"
"os"
"sync"

"github.com/pkg/errors"
)

// SvLogger is a logger object compatible with the process manager. It uses
// writer to print log to stdout or a file
type SvLogger struct {
mx sync.Mutex
writer *bufio.Writer

file *os.File
Expand All @@ -50,6 +52,9 @@ func NewSvLogger(logfilePath string) (svLogger *SvLogger, err error) {

// Write message to the file or stdout
func (l *SvLogger) Write(p []byte) (n int, err error) {
l.mx.Lock()
defer l.mx.Unlock()

return l.writer.Write(p)
}

Expand Down

0 comments on commit 0adde62

Please sign in to comment.