summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-02-16 18:18:37 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-02-16 18:18:37 +0000
commitc8dc769190404b3901a8d58ab1107c0328cd5b59 (patch)
tree5f70a53ff1e69434afea6d8ba300a8b1df69c925
parente0f4ccc46c8601f322640b72e100f973a837ef02 (diff)
fix process termination
-rw-r--r--internal/io/run/run.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/internal/io/run/run.go b/internal/io/run/run.go
index f9cd980..18e1eb9 100644
--- a/internal/io/run/run.go
+++ b/internal/io/run/run.go
@@ -69,7 +69,7 @@ func (r Run) Start(ctx context.Context, lines chan<- line.Line) (pid int, ec int
pid = r.cmd.Process.Pid
ec = 0
}
- go r.killPgroup(ctx, pid)
+ go r.killPgroup(ctx, done, pid)
var wg sync.WaitGroup
wg.Add(2)
@@ -115,7 +115,7 @@ func (r Run) PgroupKilled() <-chan struct{} {
return r.pgroupKilled
}
-func (r Run) killPgroup(ctx context.Context, pid int) {
+func (r Run) killPgroup(ctx context.Context, done chan struct{}, pid int) {
if pid == -1 {
close(r.pgroupKilled)
return
@@ -123,7 +123,10 @@ func (r Run) killPgroup(ctx context.Context, pid int) {
if pgid, err := syscall.Getpgid(pid); err == nil {
// Kill process group when done
- <-ctx.Done()
+ select {
+ case <-ctx.Done():
+ case <-done:
+ }
syscall.Kill(-pgid, syscall.SIGKILL)
close(r.pgroupKilled)
}