diff --git a/client/allocrunner/taskrunner/lifecycle.go b/client/allocrunner/taskrunner/lifecycle.go index 6ca43b6c7..ac208e723 100644 --- a/client/allocrunner/taskrunner/lifecycle.go +++ b/client/allocrunner/taskrunner/lifecycle.go @@ -78,7 +78,9 @@ func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error tr.EmitEvent(event) // Check if the Run method has started yet. If it hasn't we return early, - // since the task hasn't even started so there is nothing to wait for + // since the task hasn't even started so there is nothing to wait for. This + // is still correct since the Run method no-op since the kill context has + // already been cancelled. if !tr.hasRunLaunched() { return nil } diff --git a/client/allocrunner/taskrunner/service_hook.go b/client/allocrunner/taskrunner/service_hook.go index fdfa3d2c6..bc23e9cbc 100644 --- a/client/allocrunner/taskrunner/service_hook.go +++ b/client/allocrunner/taskrunner/service_hook.go @@ -199,6 +199,8 @@ func (h *serviceHook) getTaskServices() *agentconsul.TaskServices { // interpolateServices returns an interpolated copy of services and checks with // values from the task's environment. func interpolateServices(taskEnv *taskenv.TaskEnv, services []*structs.Service) []*structs.Service { + // Guard against not having a valid taskEnv. This can be the case if the + // Killing or Exited hook is run before post-run. if taskEnv == nil || len(services) == 0 { return nil }