Skip to content
This repository was archived by the owner on Aug 30, 2020. It is now read-only.

Commit 8d3d423

Browse files
committed
shutdown chrome to release resource
1 parent f6933d5 commit 8d3d423

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

trackers/chrome_tracker.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,25 @@ func ChromeTracker(url, xpath *string) (string, bool) {
5050
return err.Error(), false
5151
}
5252

53+
defer func() {
54+
ctx, cancel := context.WithTimeout(context.Background(), time.Second*20)
55+
if err := c.Shutdown(ctx); err != nil {
56+
log.Printf("WARN: shutdown chrome with error %s", err.Error())
57+
}
58+
cancel()
59+
}()
60+
5361
var res string
5462
tasks := chromedp.Tasks{
5563
chromedp.Navigate(*url),
5664
chromedp.Text(*xpath, &res, chromedp.NodeVisible, chromedp.BySearch),
5765
}
5866

5967
// run the tasks
60-
ctx1, cancel1 := context.WithTimeout(context.Background(), chromeTimeout)
61-
defer cancel1()
62-
if err := c.Run(ctx1, tasks); err != nil {
68+
if err := c.Run(ctx, tasks); err != nil {
6369
log.Println(err)
6470
return err.Error(), false
6571
}
72+
6673
return strings.TrimSpace(res), true
6774
}

0 commit comments

Comments
 (0)