Skip to content

Commit

Permalink
try to kill chrome when finished
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Sep 14, 2019
1 parent 97004e4 commit 63eb683
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions main.go
Expand Up @@ -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())
}

Expand All @@ -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)
Expand Down

0 comments on commit 63eb683

Please sign in to comment.