From c8dc769190404b3901a8d58ab1107c0328cd5b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Sun, 16 Feb 2020 18:18:37 +0000 Subject: fix process termination --- internal/io/run/run.go | 9 ++++++--- 1 file 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) } -- cgit v1.2.3