Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deadlock in TestPrematureCancel. #742

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion chromedp.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,11 @@ func Cancel(ctx context.Context) error {
}
// If we allocated, wait for the browser to stop, up to any possible
// deadline set in this ctx.
ready := false
if c.allocated != nil {
select {
case <-c.allocated:
ready = true
case <-ctx.Done():
}
}
Expand All @@ -227,7 +229,7 @@ func Cancel(ctx context.Context) error {
// cancelErr being ready until the allocated channel is closed, as that
// is racy. If we didn't hit ctx.Done earlier, then c.allocated was
// already cancelled then, so this will be a no-op.
if c.allocated != nil {
if !ready && c.allocated != nil {
<-c.allocated
}
return c.cancelErr
Expand Down