Skip to content

Commit

Permalink
fix: cleanup timers (#776)
Browse files Browse the repository at this point in the history
* fix: cleanup timers

* chore: bring comments back
  • Loading branch information
hayotbisonai authored Sep 16, 2024
1 parent c84d8f7 commit 40b8570
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40b8570

Please sign in to comment.