Skip to content

Commit b48e114

Browse files
committed
copy: setError should imply Close
If sending two messages from goroutine X: a <- 1 b <- 2 And receiving them in goroutine Y: select { case <- a: case <- b: } Either branch of the select can trigger first - so when we call .setError and .Close next to each other, we don't know whether the done channel will close first or the error channel will receive first - so sometimes, we get an incorrect error message. We resolve this by not sending both signals - instead, we can have .setError *imply* .Close, by having the pushWriter call .Close on itself, after receiving an error. Signed-off-by: Justin Chadwell <[email protected]>
1 parent e4f91c2 commit b48e114

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/remotes/docker/pusher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
288288
resp, err := req.doWithRetries(ctx, nil)
289289
if err != nil {
290290
pushw.setError(err)
291-
pushw.Close()
292291
return
293292
}
294293

@@ -298,7 +297,6 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
298297
err := remoteserrors.NewUnexpectedStatusErr(resp)
299298
log.G(ctx).WithField("resp", resp).WithField("body", string(err.(remoteserrors.ErrUnexpectedStatus).Body)).Debug("unexpected response")
300299
pushw.setError(err)
301-
pushw.Close()
302300
}
303301
pushw.setResponse(resp)
304302
}()
@@ -431,6 +429,7 @@ func (pw *pushWriter) Write(p []byte) (n int, err error) {
431429
select {
432430
case <-pw.done:
433431
case err = <-pw.errC:
432+
pw.Close()
434433
case p := <-pw.pipeC:
435434
return 0, pw.replacePipe(p)
436435
}
@@ -488,6 +487,7 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
488487
case <-pw.done:
489488
return io.ErrClosedPipe
490489
case err := <-pw.errC:
490+
pw.Close()
491491
return err
492492
case resp = <-pw.respC:
493493
defer resp.Body.Close()

0 commit comments

Comments
 (0)