Skip to content

Commit

Permalink
Make compressionGoroutine panic-safe again
Browse files Browse the repository at this point in the history
Commit 3250f2d 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č <[email protected]>
  • Loading branch information
mtrmac committed Jul 14, 2021
1 parent 7f15918 commit 614788f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 614788f

Please sign in to comment.