Skip to content

Commit

Permalink
Ensure that the Chrome/Chromium process is killed after use
Browse files Browse the repository at this point in the history
  • Loading branch information
michenriksen committed Apr 27, 2019
1 parent 015694a commit 155345d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion agents/url_screenshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewURLScreenshotter() *URLScreenshotter {
return &URLScreenshotter{}
}

func (d *URLScreenshotter) ID() string {
func (a *URLScreenshotter) ID() string {
return "agent:url_screenshotter"
}

Expand Down Expand Up @@ -126,6 +126,7 @@ func (a *URLScreenshotter) screenshotURL(s string) {
a.session.Out.Debug("[%s] Error: %v\n", a.ID(), err)
a.session.Stats.IncrementScreenshotFailed()
a.session.Out.Error("%s: screenshot failed: %s\n", s, err)
a.killChromeProcessIfRunning(cmd)
return
}

Expand All @@ -134,13 +135,24 @@ func (a *URLScreenshotter) screenshotURL(s string) {
a.session.Out.Debug("[%s] Error: %v\n", a.ID(), err)
if ctx.Err() == context.DeadlineExceeded {
a.session.Out.Error("%s: screenshot timed out\n", s)
a.killChromeProcessIfRunning(cmd)
return
}

a.session.Out.Error("%s: screenshot failed: %s\n", s, err)
a.killChromeProcessIfRunning(cmd)
return
}

a.session.Stats.IncrementScreenshotSuccessful()
a.session.Out.Info("%s: %s\n", s, Green("screenshot successful"))
a.killChromeProcessIfRunning(cmd)
}

func (a *URLScreenshotter) killChromeProcessIfRunning(cmd *exec.Cmd) {
if cmd.Process == nil {
return
}
cmd.Process.Release()
cmd.Process.Kill()
}

0 comments on commit 155345d

Please sign in to comment.