Skip to content

Commit a9152eb

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 b48e114 commit a9152eb

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

core/remotes/docker/pusher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ func (p dockerPusher) push(ctx context.Context, desc ocispec.Descriptor, ref str
297297
err := remoteserrors.NewUnexpectedStatusErr(resp)
298298
log.G(ctx).WithField("resp", resp).WithField("body", string(err.(remoteserrors.ErrUnexpectedStatus).Body)).Debug("unexpected response")
299299
pushw.setError(err)
300+
return
300301
}
301302
pushw.setResponse(resp)
302303
}()
@@ -432,6 +433,8 @@ func (pw *pushWriter) Write(p []byte) (n int, err error) {
432433
pw.Close()
433434
case p := <-pw.pipeC:
434435
return 0, pw.replacePipe(p)
436+
case resp := <-pw.respC:
437+
pw.setResponse(resp)
435438
}
436439
}
437440
status.Offset += int64(n)

0 commit comments

Comments
 (0)