From bdb7b93f25823c4a76d03592ab4c2baa7c30a1b9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 18 Mar 2019 10:52:18 +0100 Subject: pkg/osutil: kill subprocesses more reliably In some cases we start scp, which starts ssh, then kill scp but the ssh subprocess is not killed. As the result cmd.Wait hangs waiting for EOF on the stdout/stderr, which are still kept alive by ssh subprocess. But ssh just hangs forever. Create a process group for each command and kill whole process group. Hopefully this will help. --- pkg/osutil/osutil_linux.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pkg/osutil/osutil_linux.go') diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go index 35e5646fd..732d8e4c2 100644 --- a/pkg/osutil/osutil_linux.go +++ b/pkg/osutil/osutil_linux.go @@ -139,6 +139,12 @@ func setPdeathsig(cmd *exec.Cmd) { cmd.SysProcAttr = new(syscall.SysProcAttr) } cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL + // We will kill the whole process group. + cmd.SysProcAttr.Setpgid = true +} + +func killPgroup(cmd *exec.Cmd) { + syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) } func prolongPipe(r, w *os.File) { -- cgit mrf-deployment