Skip to content

Commit 8727463

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 a800400 commit 8727463

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

remotes/docker/pusher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
292292
resp, err := req.doWithRetries(ctx, nil)
293293
if err != nil {
294294
pushw.setError(err)
295-
pushw.Close()
296295
return
297296
}
298297

@@ -302,7 +301,6 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
302301
err := remoteserrors.NewUnexpectedStatusErr(resp)
303302
log.G(ctx).WithField("resp", resp).WithField("body", string(err.(remoteserrors.ErrUnexpectedStatus).Body)).Debug("unexpected response")
304303
pushw.setError(err)
305-
pushw.Close()
306304
}
307305
pushw.setResponse(resp)
308306
}()
@@ -435,6 +433,7 @@ func (pw *pushWriter) Write(p []byte) (n int, err error) {
435433
select {
436434
case <-pw.done:
437435
case err = <-pw.errC:
436+
pw.Close()
438437
case p := <-pw.pipeC:
439438
return 0, pw.replacePipe(p)
440439
}
@@ -492,6 +491,7 @@ func (pw *pushWriter) Commit(ctx context.Context, size int64, expected digest.Di
492491
case <-pw.done:
493492
return io.ErrClosedPipe
494493
case err := <-pw.errC:
494+
pw.Close()
495495
return err
496496
case resp = <-pw.respC:
497497
defer resp.Body.Close()

0 commit comments

Comments
 (0)