diff options
author | Valery Piashchynski <[email protected]> | 2021-12-15 00:38:41 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-12-15 00:38:41 +0300 |
commit | 33b32b1df5ad602b389925c0242c9be41b71953f (patch) | |
tree | 87fa6e2a370003a13764fed4db62245e9e1839aa | |
parent | 028ba6021e77be5e5fbde624a11254521babe3b1 (diff) |
small refactoring
Signed-off-by: Valery Piashchynski <[email protected]>
-rwxr-xr-x | pool/static_pool.go | 8 | ||||
-rwxr-xr-x | worker/worker.go | 6 |
2 files changed, 7 insertions, 7 deletions
diff --git a/pool/static_pool.go b/pool/static_pool.go index 9636f19f..4906788f 100755 --- a/pool/static_pool.go +++ b/pool/static_pool.go @@ -318,7 +318,6 @@ func (sp *StaticPool) execDebug(p *payload.Payload) (*payload.Payload, error) { }() // destroy the worker - sw.State().Set(worker.StateDestroyed) err = sw.Stop() if err != nil { sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, worker's pid: %d", err, sw.Pid()))) @@ -346,9 +345,10 @@ func (sp *StaticPool) execDebugWithTTL(ctx context.Context, p *payload.Payload) _ = sw.Wait() }() - sw.State().Set(worker.StateDestroyed) - if stopErr := sw.Stop(); stopErr != nil { - sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, pid: %d", err, sw.Pid()))) + err = sw.Stop() + if err != nil { + sp.events.Send(events.NewEvent(events.EventWorkerError, pluginName, fmt.Sprintf("error: %s, worker's pid: %d", err, sw.Pid()))) + return nil, err } return r, err diff --git a/worker/worker.go b/worker/worker.go index 0e62651d..564d83c4 100755 --- a/worker/worker.go +++ b/worker/worker.go @@ -182,24 +182,24 @@ func (w *Process) closeRelay() error { // Stop sends soft termination command to the Process and waits for process completion. func (w *Process) Stop() error { const op = errors.Op("process_stop") - w.state.Set(StateStopping) + defer w.events.Unsubscribe(w.eventsID) + select { // finished case <-w.doneCh: return nil default: + w.state.Set(StateStopping) err := internal.SendControl(w.relay, &internal.StopCommand{Stop: true}) if err != nil { w.state.Set(StateKilling) _ = w.cmd.Process.Signal(os.Kill) - w.events.Unsubscribe(w.eventsID) return errors.E(op, errors.Network, err) } <-w.doneCh w.state.Set(StateStopped) - w.events.Unsubscribe(w.eventsID) return nil } } |