From ef98e39ea936f0154dfce68b994020d38a62602d Mon Sep 17 00:00:00 2001 From: Ricardo Maraschini Date: Tue, 6 Oct 2020 10:38:23 +0200 Subject: [PATCH] Avoid deadlock by closing pipe reader end 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"). --- pkg/helpers/image/dockerlayer/add/add.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/helpers/image/dockerlayer/add/add.go b/pkg/helpers/image/dockerlayer/add/add.go index 01c6fc7805..579eadedc5 100644 --- a/pkg/helpers/image/dockerlayer/add/add.go +++ b/pkg/helpers/image/dockerlayer/add/add.go @@ -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() {