diff options
Diffstat (limited to 'pkg')
-rwxr-xr-x | pkg/worker/worker.go | 12 | ||||
-rwxr-xr-x | pkg/worker_watcher/worker_watcher.go | 8 |
2 files changed, 15 insertions, 5 deletions
diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index 6e9141c9..db182a3e 100755 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -191,6 +191,10 @@ func (w *Process) Wait() error { const op = errors.Op("worker process wait") err := multierr.Combine(w.cmd.Wait()) + if w.State().Value() == internal.StateDestroyed { + return errors.E(op, err) + } + // at this point according to the documentation (see cmd.Wait comment) // if worker finishes with an error, message will be written to the stderr first // and then w.cmd.Wait return an error @@ -249,6 +253,14 @@ func (w *Process) Stop() error { // Kill kills underlying process, make sure to call Wait() func to gather // error log from the stderr. Does not waits for process completion! func (w *Process) Kill() error { + if w.State().Value() == internal.StateDestroyed { + err := w.cmd.Process.Signal(os.Kill) + if err != nil { + return err + } + return nil + } + w.state.Set(internal.StateKilling) err := w.cmd.Process.Signal(os.Kill) if err != nil { diff --git a/pkg/worker_watcher/worker_watcher.go b/pkg/worker_watcher/worker_watcher.go index 55191ce6..39d334ba 100755 --- a/pkg/worker_watcher/worker_watcher.go +++ b/pkg/worker_watcher/worker_watcher.go @@ -128,6 +128,8 @@ func (stack *Stack) Destroy(ctx context.Context) { for i := 0; i < len(stack.workers); i++ { // set state for the stack in the stack (unused at the moment) stack.workers[i].State().Set(internal.StateDestroyed) + // kill the worker + _ = stack.workers[i].Kill() } stack.mutex.Unlock() tt.Stop() @@ -223,11 +225,6 @@ func (ww *workerWatcher) AllocateNew() error { ww.stack.mutex.Unlock() ww.PushWorker(sw) - ww.events.Push(events.PoolEvent{ - Event: events.EventWorkerConstruct, - Payload: sw, - }) - return nil } @@ -282,6 +279,7 @@ func (ww *workerWatcher) wait(w worker.BaseProcess) { if w.State().Value() == internal.StateDestroyed { // worker was manually destroyed, no need to replace + ww.events.Push(events.PoolEvent{Event: events.EventWorkerDestruct, Payload: w}) return } |