From a22205cd8f6e6d2370e6efca866cf621a83885db Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 5 Nov 2018 12:22:45 -0800 Subject: [PATCH] client: block on context as well as waitCh For lifecycle operations such as Restart and Kill, the client should not expect driver plugins to be well behaved and close their waitCh on context cancelation. Always wait on the passed in context as well as the waitCh. --- client/allocrunner/taskrunner/lifecycle.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/allocrunner/taskrunner/lifecycle.go b/client/allocrunner/taskrunner/lifecycle.go index 9083e75d7a6..224a3af6225 100644 --- a/client/allocrunner/taskrunner/lifecycle.go +++ b/client/allocrunner/taskrunner/lifecycle.go @@ -39,7 +39,10 @@ func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, fai return err } - <-waitCh + select { + case <-waitCh: + case <-ctx.Done(): + } return nil } @@ -104,7 +107,10 @@ func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error return err } - <-waitCh + select { + case <-waitCh: + case <-ctx.Done(): + } // Store that the task has been destroyed and any associated error. tr.UpdateState(structs.TaskStateDead, structs.NewTaskEvent(structs.TaskKilled).SetKillError(killErr))