diff --git a/runner/engine.go b/runner/engine.go index 22f59391..ea8dd84e 100644 --- a/runner/engine.go +++ b/runner/engine.go @@ -416,7 +416,12 @@ func (e *Engine) runBin() error { default: } }() + <-e.binStopCh + e.withLock(func() { + e.binRunning = false + }) + e.mainDebug("trying to kill pid %d, cmd %+v", cmd.Process.Pid, cmd.Args) defer func() { stdout.Close() @@ -431,9 +436,6 @@ func (e *Engine) runBin() error { } else { e.mainDebug("cmd killed, pid: %d", pid) } - e.withLock(func() { - e.binRunning = false - }) cmdBinPath := cmdPath(e.config.rel(e.config.binPath())) if _, err = os.Stat(cmdBinPath); os.IsNotExist(err) { return diff --git a/runner/util_darwin.go b/runner/util_darwin.go index 32f52cb6..57fc057c 100644 --- a/runner/util_darwin.go +++ b/runner/util_darwin.go @@ -17,10 +17,12 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) { if err = syscall.Kill(-pid, syscall.SIGINT); err != nil { return } - time.Sleep(e.config.Build.KillDelay * time.Millisecond) + time.Sleep(e.config.Build.KillDelay) } + // https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly err = syscall.Kill(-pid, syscall.SIGKILL) + // Wait releases any resources associated with the Process. _, _ = cmd.Process.Wait() return pid, err diff --git a/runner/util_linux.go b/runner/util_linux.go index f80a4a68..57fc057c 100644 --- a/runner/util_linux.go +++ b/runner/util_linux.go @@ -17,7 +17,7 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) { if err = syscall.Kill(-pid, syscall.SIGINT); err != nil { return } - time.Sleep(e.config.Build.KillDelay * time.Millisecond) + time.Sleep(e.config.Build.KillDelay) } // https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly @@ -25,7 +25,7 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) { // Wait releases any resources associated with the Process. _, _ = cmd.Process.Wait() - return + return pid, err } func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) {