Skip to content

Commit

Permalink
fix: add timer stop to avoid leak (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool committed May 12, 2023
1 parent ac9c50d commit 08fc015
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ func (e *executor) runJob(f jobFunction) {
durationToNextRun = time.Second * 5
}
if durationToNextRun > time.Millisecond*100 {
timeToSleep := time.Duration(float64(durationToNextRun) * 0.9)
timer := time.NewTimer(time.Duration(float64(durationToNextRun) * 0.9))
defer timer.Stop()

select {
case <-e.ctx.Done():
case <-time.After(timeToSleep):
case <-timer.C:
}
}
_ = l.Unlock(f.ctx)
Expand Down

0 comments on commit 08fc015

Please sign in to comment.