Skip to content

Commit f4dfa99

Browse files
authored
Merge pull request containerd#12168 from ningmingxiao/fix_lastCollection
gc:make sure lastCollection is not nil
2 parents 0ed21e1 + 683cd7d commit f4dfa99

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

plugins/gc/scheduler.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,15 @@ func (s *gcScheduler) run(ctx context.Context) {
300300
if err != nil {
301301
log.G(ctx).WithError(err).Error("garbage collection failed")
302302
collectionCounter.WithValues("fail").Inc()
303-
304-
// Reschedule garbage collection for same duration + 1 second
305-
schedC, nextCollection = schedule(nextCollection.Sub(*lastCollection) + time.Second)
303+
var retryDelay time.Duration
304+
if lastCollection != nil {
305+
// If we have a previous collection time, reschedule based on that interval.
306+
retryDelay = nextCollection.Sub(*lastCollection) + time.Second
307+
} else {
308+
// If this is the first collection and it failed, use the default schedule delay.
309+
retryDelay = s.scheduleDelay
310+
}
311+
schedC, nextCollection = schedule(retryDelay)
306312

307313
// Update last collection time even though failure occurred
308314
lastCollection = &last

0 commit comments

Comments
 (0)