From 883a95ddebad6a5cdae50499b495f074e4a1f966 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Fri, 11 Nov 2022 08:27:18 -0600 Subject: [PATCH] client: avoid unconsumed channel in timer construction 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. --- client/allocrunner/taskrunner/task_runner.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index 12f1abf26be7..4120b42ffad1 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -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: