From 99802390c19d950f2ba194dda0d6bf2d9158c717 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 2 Jul 2019 18:37:52 +0800 Subject: [PATCH] run post-run/post-stop task runner hooks Handle when prestart failed while restoring a task, to prevent accidentally leaking consul/logmon processes. --- client/allocrunner/taskrunner/task_runner.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/allocrunner/taskrunner/task_runner.go b/client/allocrunner/taskrunner/task_runner.go index cf99d8c3786..ac9d7a1c260 100644 --- a/client/allocrunner/taskrunner/task_runner.go +++ b/client/allocrunner/taskrunner/task_runner.go @@ -408,6 +408,11 @@ func (tr *TaskRunner) MarkFailedDead(reason string) { SetDisplayMessage(reason). SetFailsTask() tr.UpdateState(structs.TaskStateDead, event) + + // Run the stop hooks in case task was a restored task that failed prestart + if err := tr.stop(); err != nil { + tr.logger.Error("stop failed while marking task dead", "error", err) + } } // Run the TaskRunner. Starts the user's task or reattaches to a restored task.