From 683cd7d60d83d187ed590310d0008e38f004404e Mon Sep 17 00:00:00 2001 From: ningmingxiao Date: Tue, 5 Aug 2025 12:45:58 +0800 Subject: [PATCH] gc:make sure lastCollection is not nil Signed-off-by: ningmingxiao --- plugins/gc/scheduler.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/gc/scheduler.go b/plugins/gc/scheduler.go index ff78edee15df..65fc5d9dc763 100644 --- a/plugins/gc/scheduler.go +++ b/plugins/gc/scheduler.go @@ -300,9 +300,15 @@ func (s *gcScheduler) run(ctx context.Context) { if err != nil { log.G(ctx).WithError(err).Error("garbage collection failed") collectionCounter.WithValues("fail").Inc() - - // Reschedule garbage collection for same duration + 1 second - schedC, nextCollection = schedule(nextCollection.Sub(*lastCollection) + time.Second) + var retryDelay time.Duration + if lastCollection != nil { + // If we have a previous collection time, reschedule based on that interval. + retryDelay = nextCollection.Sub(*lastCollection) + time.Second + } else { + // If this is the first collection and it failed, use the default schedule delay. + retryDelay = s.scheduleDelay + } + schedC, nextCollection = schedule(retryDelay) // Update last collection time even though failure occurred lastCollection = &last