Skip to content

Commit

Permalink
Avoid deadlock by closing pipe reader end
Browse files Browse the repository at this point in the history
If we don't close this pipe reader with an error we ended up having a
deadlock as we keep trying to read indefinitely from it. This deadlock
causes the error message to be misguiding when attempting to upload a
layer with invalid format (gzip: invalid header).

Without this patch oc image append using an invalid layer format fails
with either "timeout" (docker.io) or "protocol error" (quay.io) instead
of reporting appropriate error ("invalid gzip").
  • Loading branch information
ricardomaraschini committed Oct 6, 2020
1 parent bdd8f89 commit ef98e39
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/helpers/image/dockerlayer/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ func DigestCopy(dst io.ReaderFrom, src io.Reader) (layerDigest, blobDigest diges
// calculate the diffID as the sha256 sum of the layer contents
pr, pw := io.Pipe()
layerhash := algo.Hash()
ch := make(chan error)
ch := make(chan error, 1)
go func() {
defer close(ch)
gr, err := gzip.NewReader(pr)
if err != nil {
ch <- fmt.Errorf("unable to create gzip reader layer upload: %v", err)
err := fmt.Errorf("unable to create gzip reader layer upload: %v", err)
pr.CloseWithError(err)
ch <- err
return
}
if !gr.Header.ModTime.IsZero() {
Expand Down

0 comments on commit ef98e39

Please sign in to comment.