Skip to content

Commit

Permalink
Fix errors when trying to kill whole process group.
Browse files Browse the repository at this point in the history
  • Loading branch information
emate committed Nov 23, 2017
1 parent f02c19e commit 9e909ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
9 changes: 8 additions & 1 deletion client/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ var (
// finishedErr is the error message received when trying to kill and already
// exited process.
finishedErr = "os: process already finished"

// noSuchProcessErr is the error message received when trying to kill a non
// existing process (e.g. when killing a process group).
noSuchProcessErr = "no such process"
)

// ClientCleanup is the cleanup routine that a Nomad Client uses to remove the
Expand All @@ -450,7 +454,10 @@ func (e *UniversalExecutor) cleanupUserLeftovers(proc *os.Process) error {
// If new process group was created upon command execution
// we can kill the whole process group now to cleanup any leftovers.
if e.cmd.SysProcAttr != nil && e.cmd.SysProcAttr.Setpgid {
return syscall.Kill(-proc.Pid, syscall.SIGKILL)
if err := syscall.Kill(-proc.Pid, syscall.SIGKILL); err != nil && err.Error() != noSuchProcessErr {
return err
}
return nil
} else {
return proc.Kill()
}
Expand Down
4 changes: 0 additions & 4 deletions client/driver/executor/executor_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func (e *UniversalExecutor) configureIsolation() error {
return nil
}

func (e *UniversalExecutor) setNewProcessGroup() error {
return nil
}

func (e *UniversalExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
pidStats, err := e.pidStats()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions client/driver/executor/executor_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package executor
import (
"fmt"
"io"
"runtime"
"syscall"

syslog "github.com/RackSec/srslog"
Expand Down Expand Up @@ -51,6 +52,10 @@ func (e *UniversalExecutor) collectLogs(we io.Writer, wo io.Writer) {

// configure new process group for child process
func (e *UniversalExecutor) setNewProcessGroup() error {
// We need to check that as build flags includes windows for this file
if runtime.GOOS == "windows" {
return nil
}
if e.cmd.SysProcAttr == nil {
e.cmd.SysProcAttr = &syscall.SysProcAttr{}
}
Expand Down

0 comments on commit 9e909ae

Please sign in to comment.