diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 170dabe2442..1f93f2070b2 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -499,7 +499,9 @@ func (ar *allocRunner) killTasks() map[string]*structs.TaskState { continue } - err := tr.Kill(context.TODO(), structs.NewTaskEvent(structs.TaskKilling)) + taskEvent := structs.NewTaskEvent(structs.TaskKilling) + taskEvent.SetKillTimeout(tr.Task().KillTimeout) + err := tr.Kill(context.TODO(), taskEvent) if err != nil && err != taskrunner.ErrTaskNotRunning { ar.logger.Warn("error stopping leader task", "error", err, "task_name", name) } @@ -519,7 +521,9 @@ func (ar *allocRunner) killTasks() map[string]*structs.TaskState { wg.Add(1) go func(name string, tr *taskrunner.TaskRunner) { defer wg.Done() - err := tr.Kill(context.TODO(), structs.NewTaskEvent(structs.TaskKilling)) + taskEvent := structs.NewTaskEvent(structs.TaskKilling) + taskEvent.SetKillTimeout(tr.Task().KillTimeout) + err := tr.Kill(context.TODO(), taskEvent) if err != nil && err != taskrunner.ErrTaskNotRunning { ar.logger.Warn("error stopping task", "error", err, "task_name", name) } diff --git a/client/allocrunner/alloc_runner_test.go b/client/allocrunner/alloc_runner_test.go index e969a31c7c0..5a758ce0a50 100644 --- a/client/allocrunner/alloc_runner_test.go +++ b/client/allocrunner/alloc_runner_test.go @@ -107,16 +107,25 @@ func TestAllocRunner_TaskLeader_KillTG(t *testing.T) { } found := false + killingMsg := "" for _, e := range state1.Events { if e.Type != structs.TaskLeaderDead { found = true } + if e.Type == structs.TaskKilling { + killingMsg = e.DisplayMessage + } } if !found { return false, fmt.Errorf("Did not find event %v", structs.TaskLeaderDead) } + expectedKillingMsg := "Sent interrupt. Waiting 10ms before force killing" + if killingMsg != expectedKillingMsg { + return false, fmt.Errorf("Unexpected task event message - wanted %q. got %q", killingMsg, expectedKillingMsg) + } + // Task Two should be dead state2 := last.TaskStates[task2.Name] if state2.State != structs.TaskStateDead {