Skip to content

Commit 520cd90

Browse files
authored
Merge pull request #5889 from hashicorp/dani/b-task-restart
tr: Fetch Wait channel before killTask in restart
2 parents 72b9b87 + 079cfb4 commit 520cd90

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

client/allocrunner/taskrunner/lifecycle.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, fai
2828
// Tell the restart tracker that a restart triggered the exit
2929
tr.restartTracker.SetRestartTriggered(failure)
3030

31+
// Grab a handle to the wait channel that will timeout with context cancelation
32+
// _before_ killing the task.
33+
waitCh, err := handle.WaitCh(ctx)
34+
if err != nil {
35+
return err
36+
}
37+
3138
// Kill the task using an exponential backoff in-case of failures.
3239
if err := tr.killTask(handle); err != nil {
3340
// We couldn't successfully destroy the resource created.
3441
tr.logger.Error("failed to kill task. Resources may have been leaked", "error", err)
3542
}
3643

37-
// Drain the wait channel or wait for the request context to be canceled
38-
waitCh, err := handle.WaitCh(ctx)
39-
if err != nil {
40-
return err
41-
}
42-
4344
select {
4445
case <-waitCh:
4546
case <-ctx.Done():

0 commit comments

Comments
 (0)