Skip to content

Commit

Permalink
Merge pull request #1112 from k1LoW/fix-race
Browse files Browse the repository at this point in the history
Fix race condition in cdp.go
  • Loading branch information
k1LoW authored Dec 12, 2024
2 parents 370f874 + bb15c53 commit 4bbdc93
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"reflect"
"sync"
"sync/atomic"
"time"

"github.com/chromedp/chromedp"
Expand Down Expand Up @@ -122,14 +123,14 @@ func (rnr *cdpRunner) run(ctx context.Context, cas CDPActions, s *step) error {
defer o.capturers.captureCDPEnd(rnr.name)

// Set a timeout (cdpTimeoutByStep) for each step because Chrome operations may get stuck depending on the actions: specified.
called := false
called := atomic.Bool{}
defer func() {
called = true
called.Store(true)
}()
timer := time.NewTimer(rnr.timeoutByStep)
go func() {
<-timer.C
if !called {
if !called.Load() {
rnr.Close()
}
}()
Expand Down

0 comments on commit 4bbdc93

Please sign in to comment.