diff --git a/pkg/storage/donut/erasure.go b/pkg/storage/donut/erasure.go index 230f83d27..53137b210 100644 --- a/pkg/storage/donut/erasure.go +++ b/pkg/storage/donut/erasure.go @@ -67,9 +67,6 @@ func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, wri summer := md5.New() params, _ := erasure.ParseEncoderParams(uint8(k), uint8(m), technique) encoder := erasure.NewEncoder(params) - for _, reader := range readers { - defer reader.Close() - } for i := 0; i < totalChunks; i++ { curBlockSize := totalLeft if blockSize < totalLeft { @@ -80,6 +77,7 @@ func erasureReader(readers []io.ReadCloser, donutMetadata map[string]string, wri encodedBytes := make([][]byte, 16) for i, reader := range readers { + defer reader.Close() var bytesBuffer bytes.Buffer _, err := io.CopyN(&bytesBuffer, reader, int64(curChunkSize)) if err != nil {