raw_exec: ensure executor is killed after task is stopped

This commit is contained in:
Nick Ethier
2019-01-25 23:06:31 -05:00
parent 3113046dc3
commit 73d5f45dd3
3 changed files with 13 additions and 0 deletions

View File

@@ -292,6 +292,8 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
procState: drivers.TaskStateRunning,
startedAt: taskState.StartedAt,
exitResult: &drivers.ExitResult{},
logger: d.logger,
doneCh: make(chan struct{}),
}
d.tasks.Set(taskState.TaskConfig.ID, h)
@@ -356,6 +358,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
procState: drivers.TaskStateRunning,
startedAt: time.Now().Round(time.Millisecond),
logger: d.logger,
doneCh: make(chan struct{}),
}
driverState := TaskState{
@@ -426,6 +429,12 @@ func (d *Driver) StopTask(taskID string, timeout time.Duration, signal string) e
return fmt.Errorf("executor Shutdown failed: %v", err)
}
// Wait for handle to finish
<-handle.doneCh
// Kill executor
handle.pluginClient.Kill()
return nil
}

View File

@@ -38,6 +38,8 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error {
procState: drivers.TaskStateRunning,
startedAt: time.Now(),
exitResult: &drivers.ExitResult{},
logger: d.logger,
doneCh: make(chan struct{}),
}
d.tasks.Set(h.Config.ID, th)

View File

@@ -26,6 +26,7 @@ type taskHandle struct {
startedAt time.Time
completedAt time.Time
exitResult *drivers.ExitResult
doneCh chan struct{}
}
func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
@@ -52,6 +53,7 @@ func (h *taskHandle) IsRunning() bool {
}
func (h *taskHandle) run() {
defer close(h.doneCh)
h.stateLock.Lock()
if h.exitResult == nil {
h.exitResult = &drivers.ExitResult{}