Bläddra i källkod

pkg/streamformatter: Make `progressOutput` concurrency safe

Sync access to the underlying `io.Writer` with a mutex.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Paweł Gronowski 1 år sedan
förälder
incheckning
5689dabfb3
1 ändrade filer med 5 tillägg och 0 borttagningar
  1. 5 0
      pkg/streamformatter/streamformatter.go

+ 5 - 0
pkg/streamformatter/streamformatter.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
+	"sync"
 
 
 	"github.com/docker/docker/pkg/jsonmessage"
 	"github.com/docker/docker/pkg/jsonmessage"
 	"github.com/docker/docker/pkg/progress"
 	"github.com/docker/docker/pkg/progress"
@@ -109,6 +110,7 @@ type progressOutput struct {
 	sf       formatProgress
 	sf       formatProgress
 	out      io.Writer
 	out      io.Writer
 	newLines bool
 	newLines bool
+	mu       sync.Mutex
 }
 }
 
 
 // WriteProgress formats progress information from a ProgressReader.
 // WriteProgress formats progress information from a ProgressReader.
@@ -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}
 		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)
 		formatted = out.sf.formatProgress(prog.ID, prog.Action, &jsonProgress, prog.Aux)
 	}
 	}
+
+	out.mu.Lock()
+	defer out.mu.Unlock()
 	_, err := out.out.Write(formatted)
 	_, err := out.out.Write(formatted)
 	if err != nil {
 	if err != nil {
 		return err
 		return err