Skip to content

Commit

Permalink
Merge pull request #314 from mimiro-io/fix/statistics
Browse files Browse the repository at this point in the history
Fix: avoid possible panic when ctx cancel is unavail
  • Loading branch information
gra-moore authored Aug 14, 2024
2 parents f8cd287 + 6c7cb22 commit df06b56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/service/scheduler/schedulable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion internal/service/scheduler/statistics_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit df06b56

Please sign in to comment.