Skip to content

Commit

Permalink
doc: event handlers sending CDP messages should run in a separate gor…
Browse files Browse the repository at this point in the history
…outine

Otherwise, it could result in a deadlock like this:
┌──────────┐          ┌─────────────┐          ┌──────────────┐
│Target.run│──waits──>│event handler│──calls──>│Target.Execute│
└────┬─────┘          └─────────────┘          └───────┬──────┘
     │                                                 │
     │                                                 │
     │             ┌──────────────────┐                │
     └────holds───>│Target.listenersMu│<────waits──────┘
                   └──────────────────┘
  • Loading branch information
ZekeLu committed May 27, 2021
1 parent 305a94b commit 004b96b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chromedp.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ type cancelableListener struct {
//
// Note that the function is called synchronously when handling events. The
// function should avoid blocking at all costs. For example, any Actions must be
// run via a separate goroutine.
// run via a separate goroutine (otherwise, it could result in a deadlock if the
// action sends CDP messages).
func ListenBrowser(ctx context.Context, fn func(ev interface{})) {
c := FromContext(ctx)
if c == nil {
Expand All @@ -674,7 +675,8 @@ func ListenBrowser(ctx context.Context, fn func(ev interface{})) {
//
// Note that the function is called synchronously when handling events. The
// function should avoid blocking at all costs. For example, any Actions must be
// run via a separate goroutine.
// run via a separate goroutine (otherwise, it could result in a deadlock if the
// action sends CDP messages).
func ListenTarget(ctx context.Context, fn func(ev interface{})) {
c := FromContext(ctx)
if c == nil {
Expand Down

0 comments on commit 004b96b

Please sign in to comment.