You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resource leak: createTSDB does not close TSDB when db.Compact() fails #7557
In pkg/ingester/ingester.go, the createTSDB function opens a TSDB via tsdb.Open() (line 2936) and later calls db.Compact() (line 2966). If Compact() returns an error, the function returns immediately without calling db.Close(), leaking the head, WAL, and mmap file handles.
Code path
// line 2936 – TSDB opened, resources acquireddb, err:= tsdb.Open(udir, ...)
iferr!=nil {
returnnil, errors.Wrapf(err, "failed to open TSDB: %s", udir)
}
db.DisableCompactions()
// line 2966 – Compact fails → return without Close → leakerr=db.Compact(context.TODO())
iferr!=nil {
returnnil, errors.Wrapf(err, "failed to compact TSDB: %s", udir) // ← db not closed
}
Impact
Each leaked TSDB holds:
Head in-memory data structures
Open WAL segment file descriptors
mmap'd chunk file descriptors
In a multi-tenant ingester under compaction pressure, repeated failures on different tenant TSDBs could exhaust file descriptors (hitting ulimit -n) and memory, eventually crashing the ingester process.
Proposed fix
Call db.Close() before returning the error from the Compact() failure path:
Activity
fix(ingester): close TSDB on compaction failure to prevent resource l…