diff --git a/client/allocrunner/alloc_runner_unix_test.go b/client/allocrunner/alloc_runner_unix_test.go index 92e956a5f..8c31832e3 100644 --- a/client/allocrunner/alloc_runner_unix_test.go +++ b/client/allocrunner/alloc_runner_unix_test.go @@ -132,7 +132,7 @@ func TestAllocRunner_Restore_RunningTerminal(t *testing.T) { require.Equal(t, events[3].Type, structs.TaskTerminated) } -// TestAllocRunner_Restore_Completed asserts that restoring a completed +// TestAllocRunner_Restore_CompletedBatch asserts that restoring a completed // batch alloc doesn't run it again func TestAllocRunner_Restore_CompletedBatch(t *testing.T) { t.Parallel() diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index c6b695fd3..233a97b11 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -401,9 +401,11 @@ func (tr *TaskRunner) Run() { // if restoring a dead task, ensure that task is cleared and all post hooks // are called without additional state updates if dead { - // clear driver handle if it was successfully restored on - // already dead task + // do cleanup functions without emitting any additional events/work + // to handle cases where we restored a dead task where client terminated + // after task finished before completing post-run actions. tr.clearDriverHandle() + tr.stateUpdater.TaskStateUpdated() if err := tr.stop(); err != nil { tr.logger.Error("stop failed on terminal task", "error", err) }