Handle case that pid is dead in ForceStop

This commit is contained in:
Alex Dadgar
2016-01-21 14:09:04 -08:00
parent 417c70c10c
commit 6620eccba9
3 changed files with 11 additions and 6 deletions

View File

@@ -120,7 +120,10 @@ func (e *BasicExecutor) ForceStop() error {
return fmt.Errorf("Failed to find user processes %v: %v", e.spawn.UserPid, err)
}
return proc.Kill()
if err := proc.Kill(); err != nil && err.Error() != "os: process already finished" {
return err
}
return nil
}
func (e *BasicExecutor) Command() *exec.Cmd {

View File

@@ -397,7 +397,7 @@ func (e *LinuxExecutor) destroyCgroup() error {
continue
}
if err := process.Kill(); err != nil {
if err := process.Kill(); err != nil && err.Error() != "os: process already finished" {
multierror.Append(errs, fmt.Errorf("Failed to kill Pid %v: %v", pid, err))
continue
}

View File

@@ -1,6 +1,7 @@
package client
import (
"fmt"
"log"
"os"
"path/filepath"
@@ -175,8 +176,9 @@ func TestTaskRunner_SaveRestoreState(t *testing.T) {
defer tr2.Destroy()
// Destroy and wait
time.Sleep(time.Duration(testutil.TestMultiplier()*5) * time.Second)
if tr2.handle == nil {
t.Fatalf("RestoreState() didn't open handle")
}
testutil.WaitForResult(func() (bool, error) {
return tr2.handle != nil, fmt.Errorf("RestoreState() didn't open handle")
}, func(err error) {
t.Fatalf("err: %v", err)
})
}