Skip to content

Commit

Permalink
pkg/streamformatter: Make progressOutput concurrency safe
Browse files Browse the repository at this point in the history
Sync access to the underlying `io.Writer` with a mutex.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
  • Loading branch information
vvoland committed Feb 22, 2024
1 parent 3865c63 commit 5689dab
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/streamformatter/streamformatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"sync"

"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/progress"
Expand Down Expand Up @@ -109,6 +110,7 @@ type progressOutput struct {
sf formatProgress
out io.Writer
newLines bool
mu sync.Mutex
}

// WriteProgress formats progress information from a ProgressReader.
Expand All @@ -120,6 +122,9 @@ func (out *progressOutput) WriteProgress(prog progress.Progress) error {
jsonProgress := jsonmessage.JSONProgress{Current: prog.Current, Total: prog.Total, HideCounts: prog.HideCounts, Units: prog.Units}
formatted = out.sf.formatProgress(prog.ID, prog.Action, &jsonProgress, prog.Aux)
}

out.mu.Lock()
defer out.mu.Unlock()
_, err := out.out.Write(formatted)
if err != nil {
return err
Expand Down

0 comments on commit 5689dab

Please sign in to comment.