diff options
| author | Paul Bütow <pbuetow@mimecast.com> | 2020-02-16 18:18:37 +0000 |
|---|---|---|
| committer | Paul Bütow <pbuetow@mimecast.com> | 2020-02-16 18:18:37 +0000 |
| commit | ec7a2c985720c9972be221ee27b41817bcc8227f (patch) | |
| tree | 5f70a53ff1e69434afea6d8ba300a8b1df69c925 /internal | |
| parent | 5ece9dc514b1fbba21e36a34f7fae42812e1d33a (diff) | |
fix process termination
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/io/run/run.go | 9 |
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) } |
