Commit a1cc8f4f authored by Kamil Trzciński's avatar Kamil Trzciński 🔴
Browse files

Properly kill processes

parent 6aa17c6a
Pipeline #2642975 failed with stage
......@@ -14,6 +14,7 @@ import (
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/executors"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/helpers"
"time"
)
type executor struct {
......@@ -104,8 +105,15 @@ func (s *executor) Run(cmd common.ExecutorCommand) error {
return err
case <-cmd.Abort:
helpers.KillProcessGroup(c)
return <-waitCh
s.Debugln("Aborting command...")
for {
helpers.KillProcessGroup(c)
select {
case <-time.After(time.Second):
case err = <-waitCh:
return err
}
}
}
}
......
......@@ -22,10 +22,10 @@ func KillProcessGroup(cmd *exec.Cmd) {
process := cmd.Process
if process != nil {
if process.Pid > 0 {
syscall.Kill(-process.Pid, syscall.SIGABRT)
syscall.Kill(-process.Pid, syscall.SIGKILL)
} else {
// doing normal kill
process.Kill()
}
// doing normal kill
process.Kill()
}
}
......@@ -209,6 +209,8 @@ func (b *AbstractShell) GenerateBuild(w ShellWriter, info common.ShellScriptInfo
b.writeExports(w, info)
b.writeCdBuildDir(w, info)
w.Notice("Running build script...")
commands := info.Build.Commands
commands = strings.TrimSpace(commands)
for _, command := range strings.Split(commands, "\n") {
......@@ -314,6 +316,8 @@ func (b *AbstractShell) GenerateAfterBuild(w ShellWriter, info common.ShellScrip
b.writeExports(w, info)
b.writeCdBuildDir(w, info)
w.Notice("Running after script...")
for _, command := range shellOptions.AfterScript {
command = strings.TrimSpace(command)
if command != "" {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment