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

[dotnet] Refactor WebSocket communication for BiDi #12614

Merged
merged 13 commits into from
Aug 29, 2023

Conversation

jimevans
Copy link
Member

@jimevans jimevans commented Aug 25, 2023

Description

Replaces the existing WebSocket communication mechanism with one more robust. Rather than immediately relying on event handlers to react to events and command reponses, it writes the incoming data to a queue which is read from a different thread. This eliminates the issue where the user might have multiple simultaneous sends or receives to the WebSocket while their event handler is running. It also dispatches incoming events on different threads for the same reason. This should eliminate at least some of the issues surrounding socket communication with bidirectional features, whether implemented using CDP or the WebDriver BiDi protocol.

Motivation and Context

In the .NET WebSocket client implementation, one can have simultaneous sends and receives, but only one of each type. This can lead to unexpected errors for users attempting to use BiDI-enabled features like network interception, where it's common to respond to an event using an event handler, and issuing another command from within the event handler body. Specific instance of a reported issue this should solve is #11536 and #10054.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Replaces the existing WebSocket communication mechanism with one more
robust. Rather than immediately relying on event handlers to react to
events and command reponses, it writes the incoming data to a queue
which is read from a different thread. This eliminates the issue where
the user might have multiple simultaneous sends or receives to the
WebSocket while their event handler is running. It also dispatches
incoming events on different threads for the same reason. This should
eliminate at least some of the issues surrounding socket communication
with bidirectional features, whether implemented using CDP or the
WebDriver BiDi protocol.
@codecov-commenter
Copy link

Codecov Report

Patch and project coverage have no change.

Comparison is base (e08916a) 57.02% compared to head (8ac0b89) 57.02%.
Report is 1 commits behind head on trunk.

❗ Current head 8ac0b89 differs from pull request most recent head d51b53c. Consider uploading reports for the commit d51b53c to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk   #12614   +/-   ##
=======================================
  Coverage   57.02%   57.02%           
=======================================
  Files          86       86           
  Lines        5322     5322           
  Branches      192      192           
=======================================
  Hits         3035     3035           
  Misses       2095     2095           
  Partials      192      192           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nvborisenko nvborisenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we don't need to put binaries to third_party/dotnet/nuget, please double check.

Looks good to me according current level of communication understanding. Thanks @jimevans for refactoring it.

@jimevans
Copy link
Member Author

@nvborisenko One was a new addition, which I forgot to add after removing the Channel-based implementation. The other was an update of a version of one already added. I've reverted that version upgrade. I believe we are ready to go with this one.

@titusfortner titusfortner merged commit 739d177 into trunk Aug 29, 2023
@titusfortner titusfortner deleted the dotnet-websocket-stability branch August 29, 2023 15:40
CandorContent pushed a commit to CandorContent/selenium that referenced this pull request Aug 30, 2023
* [dotnet] Refactor WebSocket communication for BiDi

Replaces the existing WebSocket communication mechanism with one more
robust. Rather than immediately relying on event handlers to react to
events and command reponses, it writes the incoming data to a queue
which is read from a different thread. This eliminates the issue where
the user might have multiple simultaneous sends or receives to the
WebSocket while their event handler is running. It also dispatches
incoming events on different threads for the same reason. This should
eliminate at least some of the issues surrounding socket communication
with bidirectional features, whether implemented using CDP or the
WebDriver BiDi protocol.

* Address review comments

* Removing use of System.Threading.Channels

* nitpick: fix XML doc comment

* Simplify WebSocket message queue processing code

* Omit added test from Firefox

* revert add of now unused nuget packages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants