Skip to content

Commit

Permalink
client: avoid unconsumed channel in timer construction
Browse files Browse the repository at this point in the history
This PR fixes a bug introduced in #11983 where a Timer initialized with 0
duration causes an immediate tick, even if Reset is called before reading the
channel. The fix is to avoid doing that, instead creating a Timer with a non-zero
initial wait time, and then immediately calling Stop.
  • Loading branch information
shoenig committed Nov 11, 2022
1 parent 106dce9 commit 883a95d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ func (tr *TaskRunner) Run() {
// Set the initial task state.
tr.stateUpdater.TaskStateUpdated()

timer, stop := helper.NewSafeTimer(0) // timer duration calculated JIT
// start with a stopped timer; actual restart delay computed later
timer, stop := helper.NewSafeTimer(999 * time.Hour)
timer.Stop()
defer stop()

MAIN:
Expand Down

0 comments on commit 883a95d

Please sign in to comment.