raw_exec: ensure executor is killed after task is stopped
This commit is contained in:
parent
7c61b47a6d
commit
1f4c26e19e
|
@ -292,6 +292,8 @@ func (d *Driver) RecoverTask(handle *drivers.TaskHandle) error {
|
||||||
procState: drivers.TaskStateRunning,
|
procState: drivers.TaskStateRunning,
|
||||||
startedAt: taskState.StartedAt,
|
startedAt: taskState.StartedAt,
|
||||||
exitResult: &drivers.ExitResult{},
|
exitResult: &drivers.ExitResult{},
|
||||||
|
logger: d.logger,
|
||||||
|
doneCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
d.tasks.Set(taskState.TaskConfig.ID, h)
|
d.tasks.Set(taskState.TaskConfig.ID, h)
|
||||||
|
@ -356,6 +358,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
|
||||||
procState: drivers.TaskStateRunning,
|
procState: drivers.TaskStateRunning,
|
||||||
startedAt: time.Now().Round(time.Millisecond),
|
startedAt: time.Now().Round(time.Millisecond),
|
||||||
logger: d.logger,
|
logger: d.logger,
|
||||||
|
doneCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
driverState := TaskState{
|
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)
|
return fmt.Errorf("executor Shutdown failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for handle to finish
|
||||||
|
<-handle.doneCh
|
||||||
|
|
||||||
|
// Kill executor
|
||||||
|
handle.pluginClient.Kill()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ func (d *Driver) recoverPre09Task(h *drivers.TaskHandle) error {
|
||||||
procState: drivers.TaskStateRunning,
|
procState: drivers.TaskStateRunning,
|
||||||
startedAt: time.Now(),
|
startedAt: time.Now(),
|
||||||
exitResult: &drivers.ExitResult{},
|
exitResult: &drivers.ExitResult{},
|
||||||
|
logger: d.logger,
|
||||||
|
doneCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
d.tasks.Set(h.Config.ID, th)
|
d.tasks.Set(h.Config.ID, th)
|
||||||
|
|
|
@ -26,6 +26,7 @@ type taskHandle struct {
|
||||||
startedAt time.Time
|
startedAt time.Time
|
||||||
completedAt time.Time
|
completedAt time.Time
|
||||||
exitResult *drivers.ExitResult
|
exitResult *drivers.ExitResult
|
||||||
|
doneCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
|
func (h *taskHandle) TaskStatus() *drivers.TaskStatus {
|
||||||
|
@ -52,6 +53,7 @@ func (h *taskHandle) IsRunning() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *taskHandle) run() {
|
func (h *taskHandle) run() {
|
||||||
|
defer close(h.doneCh)
|
||||||
h.stateLock.Lock()
|
h.stateLock.Lock()
|
||||||
if h.exitResult == nil {
|
if h.exitResult == nil {
|
||||||
h.exitResult = &drivers.ExitResult{}
|
h.exitResult = &drivers.ExitResult{}
|
||||||
|
|
Loading…
Reference in a new issue