diff --git a/store/snapshots/store.go b/store/snapshots/store.go index ec1d70c700f..f5dd345cb4b 100644 --- a/store/snapshots/store.go +++ b/store/snapshots/store.go @@ -153,13 +153,12 @@ func (s *Store) Load(height uint64, format uint32) (*types.Snapshot, <-chan io.R } err = func() error { defer chunk.Close() + if _, err := io.Copy(pw, chunk); err != nil { - return fmt.Errorf("failed to copy chunk %d: %w", i, err) - } - if err != nil { _ = pw.CloseWithError(err) - return err + return fmt.Errorf("failed to copy chunk %d: %w", i, err) } + return pw.Close() }() if err != nil {