Skip to content

Commit e9cb96b

Browse files
Fix flaky TestBlocksCleaner by awaiting HeartBeat goroutine completion
Signed-off-by: Artem Muterko <artem@sopho.tech>
1 parent e67fdbc commit e9cb96b

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* [BUGFIX] Ring: Fix ring token conflict resolution only applied to updated instance and make constantly token conflict check during instance observe period.
5151
* [BUGFIX] Distributor: Fix a panic (`slice bounds out of range`) in the stream push path when the context deadline expires while the worker goroutine is still marshalling a `WriteRequest`. #7541
5252
* [BUGFIX] Query Frontend: Fix native histogram responses not being handled correctly in `minTime()` sort ordering for split_by_interval merge. #7555
53+
* [BUGFIX] Compactor: Ensure visit marker heartbeat goroutine completes before blocks cleaner returns. #7386
5354

5455
## 1.21.0 2026-04-24
5556

pkg/compactor/blocks_cleaner.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,14 @@ func (c *BlocksCleaner) cleanUpActiveUsers(ctx context.Context, users []string,
357357
return nil
358358
}
359359
errChan := make(chan error, 1)
360-
go visitMarkerManager.HeartBeat(ctx, errChan, c.cleanerVisitMarkerFileUpdateInterval, true)
360+
doneChan := make(chan struct{})
361+
go func() {
362+
visitMarkerManager.HeartBeat(ctx, errChan, c.cleanerVisitMarkerFileUpdateInterval, true)
363+
close(doneChan)
364+
}()
361365
defer func() {
362366
errChan <- nil
367+
<-doneChan
363368
}()
364369
return errors.Wrapf(c.cleanUser(ctx, userLogger, userBucket, userID, firstRun), "failed to delete blocks for user: %s", userID)
365370
})
@@ -392,9 +397,14 @@ func (c *BlocksCleaner) cleanDeletedUsers(ctx context.Context, users []string) e
392397
return nil
393398
}
394399
errChan := make(chan error, 1)
395-
go visitMarkerManager.HeartBeat(ctx, errChan, c.cleanerVisitMarkerFileUpdateInterval, true)
400+
doneChan := make(chan struct{})
401+
go func() {
402+
visitMarkerManager.HeartBeat(ctx, errChan, c.cleanerVisitMarkerFileUpdateInterval, true)
403+
close(doneChan)
404+
}()
396405
defer func() {
397406
errChan <- nil
407+
<-doneChan
398408
}()
399409
return errors.Wrapf(c.deleteUserMarkedForDeletion(ctx, userLogger, userBucket, userID), "failed to delete user marked for deletion: %s", userID)
400410
})

0 commit comments

Comments
 (0)