Skip to content

Commit fb13656

Browse files
committed
Merge pull request moby#21406 from LK4D4/fix_streams_race
builder: synchronize stderr and stdout
2 parents d02d48b + 3eb0a80 commit fb13656

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

api/server/router/build/build_routes.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"strconv"
1111
"strings"
12+
"sync"
1213

1314
"github.com/Sirupsen/logrus"
1415
"github.com/docker/docker/api/server/httputils"
@@ -94,6 +95,18 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
9495
return options, nil
9596
}
9697

98+
type syncWriter struct {
99+
w io.Writer
100+
mu sync.Mutex
101+
}
102+
103+
func (s *syncWriter) Write(b []byte) (count int, err error) {
104+
s.mu.Lock()
105+
count, err = s.w.Write(b)
106+
s.mu.Unlock()
107+
return
108+
}
109+
97110
func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
98111
var (
99112
authConfigs = map[string]types.AuthConfig{}
@@ -172,6 +185,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
172185
if buildOptions.SuppressOutput {
173186
out = notVerboseBuffer
174187
}
188+
out = &syncWriter{w: out}
175189
stdout := &streamformatter.StdoutFormatter{Writer: out, StreamFormatter: sf}
176190
stderr := &streamformatter.StderrFormatter{Writer: out, StreamFormatter: sf}
177191

0 commit comments

Comments
 (0)