diff options
Diffstat (limited to 'pipe_factory.go')
-rwxr-xr-x | pipe_factory.go | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/pipe_factory.go b/pipe_factory.go index d6242775..15f38e42 100755 --- a/pipe_factory.go +++ b/pipe_factory.go @@ -2,9 +2,7 @@ package roadrunner import ( "context" - "fmt" "os/exec" - "strings" "github.com/spiral/errors" "github.com/spiral/goridge/v2" @@ -33,12 +31,13 @@ type SpawnResult struct { // method Wait() must be handled on level above. func (f *PipeFactory) SpawnWorkerWithContext(ctx context.Context, cmd *exec.Cmd) (WorkerBase, error) { c := make(chan SpawnResult) + const op = errors.Op("spawn worker with context") go func() { w, err := InitBaseWorker(cmd) if err != nil { c <- SpawnResult{ w: nil, - err: err, + err: errors.E(op, err), } return } @@ -48,7 +47,7 @@ func (f *PipeFactory) SpawnWorkerWithContext(ctx context.Context, cmd *exec.Cmd) if err != nil { c <- SpawnResult{ w: nil, - err: err, + err: errors.E(op, err), } return } @@ -58,7 +57,7 @@ func (f *PipeFactory) SpawnWorkerWithContext(ctx context.Context, cmd *exec.Cmd) if err != nil { c <- SpawnResult{ w: nil, - err: err, + err: errors.E(op, err), } return } @@ -72,7 +71,7 @@ func (f *PipeFactory) SpawnWorkerWithContext(ctx context.Context, cmd *exec.Cmd) if err != nil { c <- SpawnResult{ w: nil, - err: errors.E(err, "process error"), + err: errors.E(op, err, "process error"), } return } @@ -87,7 +86,7 @@ func (f *PipeFactory) SpawnWorkerWithContext(ctx context.Context, cmd *exec.Cmd) ) c <- SpawnResult{ w: nil, - err: err, + err: errors.E(op, err), } return } @@ -117,19 +116,19 @@ func (f *PipeFactory) SpawnWorker(cmd *exec.Cmd) (WorkerBase, error) { const op = errors.Op("spawn worker") w, err := InitBaseWorker(cmd) if err != nil { - return nil, err + return nil, errors.E(op, err) } // TODO why out is in? in, err := cmd.StdoutPipe() if err != nil { - return nil, err + return nil, errors.E(op, err) } // TODO why in is out? out, err := cmd.StdinPipe() if err != nil { - return nil, err + return nil, errors.E(op, err) } // Init new PIPE relay @@ -143,24 +142,13 @@ func (f *PipeFactory) SpawnWorker(cmd *exec.Cmd) (WorkerBase, error) { } // errors bundle - var errs []string - if pid, errF := fetchPID(relay); pid != w.Pid() { - if errF != nil { - errs = append(errs, errF.Error()) - } - - errK := w.Kill() - if errK != nil { - errs = append(errs, fmt.Errorf("error killing the worker with PID number %d, Created: %s", w.Pid(), w.Created()).Error()) - } - - if wErr := w.Wait(context.Background()); wErr != nil { - errs = append(errs, wErr.Error()) - } - - if len(errs) > 0 { - return nil, errors.E(op, strings.Join(errs, "/")) - } + if pid, err := fetchPID(relay); pid != w.Pid() { + err = multierr.Combine( + err, + w.Kill(), + w.Wait(context.Background()), + ) + return nil, errors.E(op, err) } // everything ok, set ready state |