mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
cleanup: prevent leaks from time.After
This PR replaces use of time.After with a safe helper function that creates a time.Timer to use instead. The new function returns both a time.Timer and a Stop function that the caller must handle. Unlike time.NewTimer, the helper function does not panic if the duration set is <= 0.
This commit is contained in:
@@ -527,6 +527,9 @@ func (tr *TaskRunner) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
timer, stop := helper.NewSafeTimer(0) // timer duration calculated JIT
|
||||
defer stop()
|
||||
|
||||
MAIN:
|
||||
for !tr.shouldShutdown() {
|
||||
select {
|
||||
@@ -612,9 +615,11 @@ MAIN:
|
||||
break MAIN
|
||||
}
|
||||
|
||||
timer.Reset(restartDelay)
|
||||
|
||||
// Actually restart by sleeping and also watching for destroy events
|
||||
select {
|
||||
case <-time.After(restartDelay):
|
||||
case <-timer.C:
|
||||
case <-tr.killCtx.Done():
|
||||
tr.logger.Trace("task killed between restarts", "delay", restartDelay)
|
||||
break MAIN
|
||||
|
||||
Reference in New Issue
Block a user