client: simplify kill logic

Remove runLaunched tracking as Run is *always* called for killable
TaskRunners. TaskRunners which fail before Run can be called (during
NewTaskRunner or Restore) are not killable as they're never added to the
client's alloc map.
This commit is contained in:
Michael Schurter
2019-04-04 15:18:33 -07:00
parent 010b9575db
commit 3bad050bf1
3 changed files with 0 additions and 31 deletions

View File

@@ -77,14 +77,6 @@ func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error
// Emit kill event
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. This
// is still correct since the Run method no-op since the kill context has
// already been cancelled.
if !tr.hasRunLaunched() {
return nil
}
select {
case <-tr.WaitCh():
case <-ctx.Done():

View File

@@ -190,11 +190,6 @@ type TaskRunner struct {
// handlers
driverManager drivermanager.Manager
// runLaunched marks whether the Run goroutine has been started. It should
// be accessed via helpers
runLaunched bool
runLaunchedLock sync.Mutex
// maxEvents is the capacity of the TaskEvents on the TaskState.
// Defaults to defaultMaxEvents but overrideable for testing.
maxEvents int
@@ -378,10 +373,6 @@ func (tr *TaskRunner) initLabels() {
// Run the TaskRunner. Starts the user's task or reattaches to a restored task.
// Run closes WaitCh when it exits. Should be started in a goroutine.
func (tr *TaskRunner) Run() {
// Mark that the run routine has been launched so that other functions can
// decide to use the wait channel or not.
tr.setRunLaunched()
defer close(tr.waitCh)
var result *drivers.ExitResult

View File

@@ -101,20 +101,6 @@ func (tr *TaskRunner) getKillErr() error {
return tr.killErr
}
// setRunLaunched marks the fact that the Run loop has been started
func (tr *TaskRunner) setRunLaunched() {
tr.runLaunchedLock.Lock()
defer tr.runLaunchedLock.Unlock()
tr.runLaunched = true
}
// hasRunLaunched returns whether the Run loop has been started
func (tr *TaskRunner) hasRunLaunched() bool {
tr.runLaunchedLock.Lock()
defer tr.runLaunchedLock.Unlock()
return tr.runLaunched
}
// hookState returns the state for the given hook or nil if no state is
// persisted for the hook.
func (tr *TaskRunner) hookState(name string) *state.HookState {