From 10e676923c9bd9f7832fae618da15ca3f7f7f8ea Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Thu, 8 Apr 2021 16:31:37 -0700 Subject: [PATCH] logger: fix concurrency issue Signed-off-by: Andrea Luzzardi --- cmd/dagger/logger/console.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/dagger/logger/console.go b/cmd/dagger/logger/console.go index 39e1476a..7e1aaccd 100644 --- a/cmd/dagger/logger/console.go +++ b/cmd/dagger/logger/console.go @@ -7,6 +7,7 @@ import ( "hash/adler32" "io" "strings" + "sync" "time" "github.com/mitchellh/colorstring" @@ -21,6 +22,7 @@ var colorize = colorstring.Colorize{ type Console struct { Out io.Writer maxLength int + l sync.Mutex } func (c *Console) Write(p []byte) (n int, err error) { @@ -31,9 +33,12 @@ func (c *Console) Write(p []byte) (n int, err error) { } source := c.parseSource(event) + + c.l.Lock() if len(source) > c.maxLength { c.maxLength = len(source) } + c.l.Unlock() return fmt.Fprintln(c.Out, colorize.Color(fmt.Sprintf("%s %s %s%s%s",