fix: cleanup timers (#776)

* fix: cleanup timers

* chore: bring comments back
This commit is contained in:
Barkhayot 2024-09-16 23:57:39 +09:00 committed by GitHub
parent c84d8f70c4
commit 40b8570e23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 0 deletions

View File

@ -359,6 +359,13 @@ func (s *scheduler) selectExecJobsOutForRescheduling(id uuid.UUID) {
next = j.next(next) 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.nextScheduled = append(j.nextScheduled, next)
j.timer = s.exec.clock.AfterFunc(next.Sub(s.now()), func() { j.timer = s.exec.clock.AfterFunc(next.Sub(s.now()), func() {
// set the actual timer on the job here and listen for // set the actual timer on the job here and listen for