From 2ba6aee738e6d3b4c5942afbe52738b4ec5ac393 Mon Sep 17 00:00:00 2001 From: Marcin Matlaszek Date: Thu, 23 Nov 2017 11:57:26 +0100 Subject: [PATCH] Fix errors when trying to kill whole process group. --- client/driver/executor/executor.go | 9 ++++++++- client/driver/executor/executor_basic.go | 4 ---- client/driver/executor/executor_unix.go | 5 +++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client/driver/executor/executor.go b/client/driver/executor/executor.go index 53d6aa4bf0a0..d47930b7c125 100644 --- a/client/driver/executor/executor.go +++ b/client/driver/executor/executor.go @@ -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 @@ -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() } diff --git a/client/driver/executor/executor_basic.go b/client/driver/executor/executor_basic.go index 65030d45b44d..123ed47032e2 100644 --- a/client/driver/executor/executor_basic.go +++ b/client/driver/executor/executor_basic.go @@ -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 { diff --git a/client/driver/executor/executor_unix.go b/client/driver/executor/executor_unix.go index cf2fc3f33440..81b79e6f4bd0 100644 --- a/client/driver/executor/executor_unix.go +++ b/client/driver/executor/executor_unix.go @@ -5,6 +5,7 @@ package executor import ( "fmt" "io" + "runtime" "syscall" syslog "github.com/RackSec/srslog" @@ -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{} }