From a2b5d72b2de98b6bf4079010cb52dbb70fc23b3e Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 3 Oct 2023 16:17:53 -0700 Subject: [PATCH] respect the contexts a little better --- bgs/bgs.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bgs/bgs.go b/bgs/bgs.go index c3501ff41..04d475ae4 100644 --- a/bgs/bgs.go +++ b/bgs/bgs.go @@ -1227,6 +1227,15 @@ func (bgs *BGS) runRepoCompaction(ctx context.Context, lim int, dry bool) (*comp results := make(map[models.Uid]*carstore.CompactionStats) for _, r := range repos { + select { + case <-ctx.Done(): + return &compactionStats{ + Targets: repos, + Completed: results, + }, nil + default: + } + st, err := bgs.repoman.CarStore().CompactUserShards(context.Background(), r.Usr) if err != nil { log.Errorf("failed to compact shards for user %d: %s", r.Usr, err)