Skip to content

goroutine leak in openIndexV12 and openTSDBIndex #4227

@liaol

Description

@liaol

I identified a goroutine leak with github.com/minio/minio-go/v7.(*Client).GetObject.func1 when use S3 objstore
The root cause is that the Close method is not called on the return value of bucket.Get in these two methods.

func (r *Reader) openIndexV12(ctx context.Context) error {
f, err := r.lookupFile(IndexFileName)
if err != nil {
return err
}
o, err := r.bucket.Get(ctx, f.RelPath)
if err != nil {
return err
}
b, err := io.ReadAll(o)
if err != nil {
return err
}
r.index, err = OpenIndex(b)
return err
}

func (q *singleBlockQuerier) openTSDBIndex(ctx context.Context) error {
f, err := q.bucket.Get(ctx, block.IndexFilename)
if err != nil {
return fmt.Errorf("opening index.tsdb file: %w", err)
}
var buf []byte
var tsdbIndexFile block.File
for _, mf := range q.meta.Files {
if mf.RelPath == block.IndexFilename {
tsdbIndexFile = mf
break
}
}
if tsdbIndexFile.SizeBytes > 0 {
// If index size is known beforehand, we can allocate
// a buffer of the exact size to save some space.
buf = make([]byte, tsdbIndexFile.SizeBytes)
_, err = io.ReadFull(f, buf)
} else {
// 32KB is the default buf size of io.Copy.
// It's unlikely that a tsdb index is less than that.
b := bytes.NewBuffer(make([]byte, 0, 32<<10))
_, err = io.Copy(b, f)
buf = b.Bytes()
}
if err != nil {
return fmt.Errorf("reading tsdb index: %w", err)
}
q.index, err = index.NewReader(index.RealByteSlice(buf))
if err != nil {
return fmt.Errorf("opening tsdb index: %w", err)
}
return nil
}

If confirmed, I can submit a CR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions