Skip to content

Commit

Permalink
Merge pull request #17 from bundleman/fix-cdp
Browse files Browse the repository at this point in the history
fix(drivers): fix routines leakage
  • Loading branch information
bundleman authored Jan 27, 2022
2 parents 087116c + b7375ba commit 1ebe3c9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/drivers/cdp/network/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newNavigationEventStream(
func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Message {
ch := make(chan rtEvents.Message)

ctx, cancel := context.WithCancel(context.Background())
go func() {
defer close(ch)

Expand All @@ -54,16 +55,15 @@ func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Messag
return
case <-s.onDoc.Ready():
if ctx.Err() != nil {
return
cancel()
}

repl, err := s.onDoc.Recv()

if err != nil {
ch <- rtEvents.WithErr(err)
s.logger.Trace().Err(err).Msg("failed to read data from within document navigation event stream")

return
cancel()
}

evt := NavigationEvent{
Expand All @@ -80,9 +80,11 @@ func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Messag
s.tail.Store(evt)

ch <- rtEvents.WithValue(&evt)
cancel()

case <-s.onFrame.Ready():
if ctx.Err() != nil {
return
cancel()
}

repl, err := s.onFrame.Recv()
Expand All @@ -91,7 +93,7 @@ func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Messag
ch <- rtEvents.WithErr(err)
s.logger.Trace().Err(err).Msg("failed to read data from frame navigation event stream")

return
cancel()
}

evt := NavigationEvent{
Expand All @@ -109,6 +111,7 @@ func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Messag
s.tail.Store(evt)

ch <- rtEvents.WithValue(&evt)
cancel()
}
}
}()
Expand Down

0 comments on commit 1ebe3c9

Please sign in to comment.