From 6c7cb225f1a0b483ccbacbda85c8c6a4c5930c6b Mon Sep 17 00:00:00 2001 From: Sven Eigenbrodt Date: Wed, 14 Aug 2024 09:11:11 +0200 Subject: [PATCH] avoid possible panic when ctx cancel is unavail --- internal/service/scheduler/schedulable.go | 5 +++++ internal/service/scheduler/statistics_update.go | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/service/scheduler/schedulable.go b/internal/service/scheduler/schedulable.go index 7ce0ea9..9dae5bf 100644 --- a/internal/service/scheduler/schedulable.go +++ b/internal/service/scheduler/schedulable.go @@ -76,6 +76,11 @@ func newSchedulableTask(taskId string, immediateRun bool, logger *zap.SugaredLog func (s *schedulableTask) Run() { s.lock.Lock() + if s.state == TaskStateRunning { + s.logger.Infof("Task %s is already running", s.ID()) + s.lock.Unlock() + return + } s.state = TaskStateRunning s.lock.Unlock() diff --git a/internal/service/scheduler/statistics_update.go b/internal/service/scheduler/statistics_update.go index 4eed775..36b68a5 100644 --- a/internal/service/scheduler/statistics_update.go +++ b/internal/service/scheduler/statistics_update.go @@ -54,7 +54,9 @@ func NewStatisticsUpdater(logger *zap.SugaredLogger, store store.BadgerStore) sc ctx, cancel := context.WithCancel(context.Background()) stats.cancel = cancel defer func() { - stats.cancel() + if stats.cancel != nil { + stats.cancel() + } stats.cancel = nil }() stats.Logger.Infof("gathering counts for all datasets")