Skip to content

Commit

Permalink
Merge pull request #1297 from mtrmac/goroutine-patic
Browse files Browse the repository at this point in the history
Make compressionGoroutine panic-safe again
  • Loading branch information
mtrmac authored Jul 14, 2021
2 parents 7f15918 + 614788f commit 2b688e9
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 2b688e9

Please sign in to comment.