diff --git a/block.go b/block.go index 08b4861f8..002ed1beb 100644 --- a/block.go +++ b/block.go @@ -277,9 +277,10 @@ func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, er var closers []io.Closer defer func() { if err != nil { - for _, c := range closers { - c.Close() - } + var merr MultiError + merr.Add(err) + merr.Add(closeAll(closers)) + err = merr.Err() } }() meta, err := readMetaFile(dir) diff --git a/chunks/chunks.go b/chunks/chunks.go index 3f65bfa6a..f0f5ac776 100644 --- a/chunks/chunks.go +++ b/chunks/chunks.go @@ -342,7 +342,7 @@ func NewDirReader(dir string, pool chunkenc.Pool) (*Reader, error) { } func (s *Reader) Close() error { - return closeAll(s.cs...) + return closeAll(s.cs) } // Size returns the size of the chunks. @@ -410,7 +410,7 @@ func sequenceFiles(dir string) ([]string, error) { return res, nil } -func closeAll(cs ...io.Closer) (err error) { +func closeAll(cs []io.Closer) (err error) { for _, c := range cs { if e := c.Close(); e != nil { err = e diff --git a/compact.go b/compact.go index 4025b12d7..265cda0b8 100644 --- a/compact.go +++ b/compact.go @@ -582,7 +582,7 @@ func (c *LeveledCompactor) write(dest string, meta *BlockMeta, blocks ...BlockRe // populateBlock fills the index and chunk writers with new data gathered as the union // of the provided blocks. It returns meta information for the new block. -func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta, indexw IndexWriter, chunkw ChunkWriter) error { +func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta, indexw IndexWriter, chunkw ChunkWriter) (err error) { if len(blocks) == 0 { return errors.New("cannot populate block from no readers") } @@ -592,7 +592,12 @@ func (c *LeveledCompactor) populateBlock(blocks []BlockReader, meta *BlockMeta, allSymbols = make(map[string]struct{}, 1<<16) closers = []io.Closer{} ) - defer func() { closeAll(closers...) }() + defer func() { + var merr MultiError + merr.Add(err) + merr.Add(closeAll(closers)) + err = merr.Err() + }() for i, b := range blocks { indexr, err := b.Index() diff --git a/db.go b/db.go index 3bce5b08b..e8fd9c0aa 100644 --- a/db.go +++ b/db.go @@ -1097,7 +1097,7 @@ func (es MultiError) Err() error { return es } -func closeAll(cs ...io.Closer) error { +func closeAll(cs []io.Closer) error { var merr MultiError for _, c := range cs {