Skip to content

Commit 52a1402

Browse files
committed
copy: prevent potential deadlock if close before fully written
We also need an additional check to avoid setting both the error and response which can create a race where they can arrive in the receiving thread in either order. If we hit an error, we don't need to send the response. > There is a condition where the registry (unexpectedly, not to spec) > returns 201 or 204 on the put before the body is fully written. I would > expect that the http library would issue close and could fall into a > deadlock here. We could just read respC and call setResponse. In that > case ErrClosedPipe would get returned and Commit shouldn't be called > anyway. Signed-off-by: Justin Chadwell <[email protected]>
1 parent 8727463 commit 52a1402

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

remotes/docker/pusher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
301301
err := remoteserrors.NewUnexpectedStatusErr(resp)
302302
log.G(ctx).WithField("resp", resp).WithField("body", string(err.(remoteserrors.ErrUnexpectedStatus).Body)).Debug("unexpected response")
303303
pushw.setError(err)
304+
return
304305
}
305306
pushw.setResponse(resp)
306307
}()
@@ -436,6 +437,8 @@ func (pw *pushWriter) Write(p []byte) (n int, err error) {
436437
pw.Close()
437438
case p := <-pw.pipeC:
438439
return 0, pw.replacePipe(p)
440+
case resp := <-pw.respC:
441+
pw.setResponse(resp)
439442
}
440443
}
441444
status.Offset += int64(n)

0 commit comments

Comments
 (0)