diff --git a/pkg/drivers/cdp/network/streams.go b/pkg/drivers/cdp/network/streams.go index 74753e96..7d0a2ab6 100644 --- a/pkg/drivers/cdp/network/streams.go +++ b/pkg/drivers/cdp/network/streams.go @@ -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) @@ -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{ @@ -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() @@ -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{ @@ -109,6 +111,7 @@ func (s *NavigationEventStream) Read(ctx context.Context) <-chan rtEvents.Messag s.tail.Store(evt) ch <- rtEvents.WithValue(&evt) + cancel() } } }()