From 63eb683528be3978b444369de14b3d87e670364a Mon Sep 17 00:00:00 2001 From: Christian Mehlmauer Date: Sat, 14 Sep 2019 16:53:59 +0200 Subject: [PATCH] try to kill chrome when finished --- main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.go b/main.go index fc69db1..5985390 100644 --- a/main.go +++ b/main.go @@ -115,6 +115,7 @@ func execChrome(ctxMain context.Context, action, url string, w, h int) ([]byte, cmd.Stderr = &stderr err = cmd.Run() if err != nil { + killChromeProcessIfRunning(cmd) return nil, fmt.Errorf("could not execute command %v: %s", err, stderr.String()) } @@ -134,9 +135,19 @@ func execChrome(ctxMain context.Context, action, url string, w, h int) ([]byte, return nil, fmt.Errorf("could not read temp file %v", err) } + killChromeProcessIfRunning(cmd) + return content, nil } +func killChromeProcessIfRunning(cmd *exec.Cmd) { + if cmd.Process == nil { + return + } + cmd.Process.Release() + cmd.Process.Kill() +} + func (app *application) logError(w http.ResponseWriter, err error, withTrace bool) { w.Header().Set("Connection", "close") errorText := fmt.Sprintf("%v", err)