From 614788f088cfc4dbc6fdb737e11530f8f3a53bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Fri, 9 Jul 2021 12:44:41 +0200 Subject: [PATCH] Make compressionGoroutine panic-safe again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 3250f2da77d61931d38513846f2bb7fbf9352460 removed the code that ensures the pipe is closed with error on a goroutine panic, i.e. that the caller does not hang indefinitely, for no clear reason; restore that. Signed-off-by: Miloslav Trmač --- copy/copy.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/copy/copy.go b/copy/copy.go index ae182777b7..9bc479d234 100644 --- a/copy/copy.go +++ b/copy/copy.go @@ -1752,6 +1752,10 @@ func doCompression(dest io.Writer, src io.Reader, metadata map[string]string, co // compressGoroutine reads all input from src and writes its compressed equivalent to dest. func (c *copier) compressGoroutine(dest *io.PipeWriter, src io.Reader, metadata map[string]string, compressionFormat compression.Algorithm) { - err := doCompression(dest, src, metadata, compressionFormat, c.compressionLevel) - _ = dest.CloseWithError(err) // CloseWithError(nil) is equivalent to Close(), always returns nil + err := errors.New("Internal error: unexpected panic in compressGoroutine") + defer func() { // Note that this is not the same as {defer dest.CloseWithError(err)}; we need err to be evaluated lazily. + _ = dest.CloseWithError(err) // CloseWithError(nil) is equivalent to Close(), always returns nil + }() + + err = doCompression(dest, src, metadata, compressionFormat, c.compressionLevel) }