Skip to content

Commit 5689dab

Browse files
committed
pkg/streamformatter: Make progressOutput concurrency safe
Sync access to the underlying `io.Writer` with a mutex. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 3865c63 commit 5689dab

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

pkg/streamformatter/streamformatter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"sync"
89

910
"github.com/docker/docker/pkg/jsonmessage"
1011
"github.com/docker/docker/pkg/progress"
@@ -109,6 +110,7 @@ type progressOutput struct {
109110
sf formatProgress
110111
out io.Writer
111112
newLines bool
113+
mu sync.Mutex
112114
}
113115

114116
// WriteProgress formats progress information from a ProgressReader.
@@ -120,6 +122,9 @@ func (out *progressOutput) WriteProgress(prog progress.Progress) error {
120122
jsonProgress := jsonmessage.JSONProgress{Current: prog.Current, Total: prog.Total, HideCounts: prog.HideCounts, Units: prog.Units}
121123
formatted = out.sf.formatProgress(prog.ID, prog.Action, &jsonProgress, prog.Aux)
122124
}
125+
126+
out.mu.Lock()
127+
defer out.mu.Unlock()
123128
_, err := out.out.Write(formatted)
124129
if err != nil {
125130
return err

0 commit comments

Comments
 (0)