From ef6ae16fa4051ca4c21a95f7a071365c2a01d4d6 Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Wed, 24 Aug 2022 16:45:01 -0400 Subject: [PATCH] minor fixes --- client/allocrunner/taskrunner/task_runner.go | 10 +++++----- client/allocrunner/taskrunner/task_runner_test.go | 4 ++-- website/content/docs/commands/alloc/restart.mdx | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index c6899d1f938f..445cf044038c 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -518,10 +518,10 @@ func (tr *TaskRunner) Run() { runComplete := tr.localState.RunComplete tr.stateLock.RUnlock() - // If restoring a dead task, ensure that task is cleared and all post hooks - // are called without additional state updates. - // If the alloc is not terminal we must proceed until the ALLOC_RESTART - // loop to allow the task to run again in case the alloc is restarted. + // If restoring a dead task, ensure the task is cleared and, if the local + // state indicates that the previous Run() call is complete, execute all + // post stop hooks and exit early, otherwise proceed until the + // ALLOC_RESTART loop skipping MAIN since the task is dead. if dead { // do cleanup functions without emitting any additional events/work // to handle cases where we restored a dead task where client terminated @@ -686,7 +686,7 @@ MAIN: tr.UpdateState(structs.TaskStateDead, nil) // Wait here in case the allocation is restarted. Poststop tasks will never - // run again so, skip them to avoid blocking forever. + // run again so skip them to avoid blocking forever. if !tr.Task().IsPoststop() { ALLOC_RESTART: // Run in a loop to handle cases where restartCh is triggered but the diff --git a/client/allocrunner/taskrunner/task_runner_test.go b/client/allocrunner/taskrunner/task_runner_test.go index 53ffbf87e301..87a64d767ca5 100644 --- a/client/allocrunner/taskrunner/task_runner_test.go +++ b/client/allocrunner/taskrunner/task_runner_test.go @@ -398,7 +398,7 @@ func TestTaskRunner_Restore_Dead(t *testing.T) { // Retry a few times as the newTR.Run() may not have started yet. testutil.WaitForResult(func() (bool, error) { ev := &structs.TaskEvent{Type: structs.TaskRestartSignal} - err = newTR.Rerun(context.Background(), ev, false) + err = newTR.ForceRestart(context.Background(), ev, false) return err == nil, err }, func(err error) { require.NoError(t, err) @@ -426,7 +426,7 @@ func TestTaskRunner_Restore_Dead(t *testing.T) { defer newTR2.Kill(context.Background(), structs.NewTaskEvent("cleanup")) ev := &structs.TaskEvent{Type: structs.TaskRestartSignal} - err = newTR2.Rerun(context.Background(), ev, false) + err = newTR2.ForceRestart(context.Background(), ev, false) require.Equal(t, err, ErrTaskNotRunning) } diff --git a/website/content/docs/commands/alloc/restart.mdx b/website/content/docs/commands/alloc/restart.mdx index ece6fde933f6..32f14b6e8349 100644 --- a/website/content/docs/commands/alloc/restart.mdx +++ b/website/content/docs/commands/alloc/restart.mdx @@ -39,7 +39,8 @@ allocation's namespace. ## Restart Options - `-all-tasks`: If set, all tasks in the allocation will be restarted, even the - ones that already ran. This option cannot be used if a task is defined. + ones that already ran. This option cannot be used with `-task` or the + `` argument. - `-task`: Specify the individual task to restart. This option cannot be used with `-all-tasks`.