Skip to content

Commit

Permalink
fix: cleanup timers (go-co-op#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 b2341c2 commit 431d469
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 431d469

Please sign in to comment.