Skip to content

Commit

Permalink
client: block on context as well as waitCh
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
schmichael committed Nov 5, 2018
1 parent 740ca8e commit a22205c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/allocrunner/taskrunner/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a22205c

Please sign in to comment.