From 431d469b4caacbd31f45c81d78a277d621327371 Mon Sep 17 00:00:00 2001 From: Barkhayot <157342287+hayotbisonai@users.noreply.github.com> Date: Mon, 16 Sep 2024 23:57:39 +0900 Subject: [PATCH] fix: cleanup timers (#776) * fix: cleanup timers * chore: bring comments back --- scheduler.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scheduler.go b/scheduler.go index ec740042..90ff5212 100644 --- a/scheduler.go +++ b/scheduler.go @@ -359,6 +359,13 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) { next = j.next(next) } } + + // Clean up any existing timer to prevent leaks + if j.timer != nil { + j.timer.Stop() + j.timer = nil // Ensure timer is cleared for GC + } + j.nextScheduled = append(j.nextScheduled, next) j.timer = s.exec.clock.AfterFunc(next.Sub(s.now()), func() { // set the actual timer on the job here and listen for