diff --git a/pkg/compact/compact.go b/pkg/compact/compact.go index 32381168b7..dd342d04ff 100644 --- a/pkg/compact/compact.go +++ b/pkg/compact/compact.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "sort" + "strings" "sync" "time" @@ -884,6 +885,21 @@ func (cg *Group) Compact(ctx context.Context, dir string, planner Planner, comp return false, ulid.ULID{}, errors.Wrap(err, "create compaction group dir") } + defer func() { + if p := recover(); p != nil { + var sb strings.Builder + + cgIDs := cg.IDs() + for i, blid := range cgIDs { + _, _ = sb.WriteString(blid.String()) + if i < len(cgIDs)-1 { + _, _ = sb.WriteString(",") + } + } + rerr = fmt.Errorf("paniced while compacting %s: %v", sb.String(), p) + } + }() + errChan := make(chan error, 1) err := tracing.DoInSpanWithErr(ctx, "compaction_group", func(ctx context.Context) (err error) { shouldRerun, compID, err = cg.compact(ctx, subDir, planner, comp, blockDeletableChecker, compactionLifecycleCallback, errChan)