-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[rb] add synchronization and error handling for socket interactions #16487
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
base: trunk
Are you sure you want to change the base?
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||||||||
PR Code Suggestions ✨Latest suggestions up to 627943c
Previous suggestions✅ Suggestions up to commit 4292334
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds thread safety and improved error handling to WebSocket connection management in the Ruby Selenium bindings to prevent IOError exceptions during JRuby shutdown. The changes focus on synchronizing concurrent access to shared resources, gracefully handling connection errors, and properly coordinating shutdown sequences.
Key changes:
- Added mutex synchronization around all WebSocket callback and message operations
- Expanded connection error handling to include EBADF, IOError, and EOFError
- Implemented graceful shutdown using thread joining instead of forced exits
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| websocket_connection.rb | Added mutex synchronization, graceful shutdown with @closing flag, and enhanced error handling for socket operations |
| bidi_bridge.rb | Reordered quit sequence to close BiDi connection before parent HTTP connection |
| bridge.rb | Expanded QUIT_ERRORS list and improved error handling in quit method |
| test_environment.rb | Added --disable-dev-shm-usage flag for Chrome/Edge when running on RBE |
| driver_spec.rb | Simplified test exclusion metadata |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
68b4677 to
11def6f
Compare
11def6f to
627943c
Compare
User description
🔗 Related Issues
In the process of this PR - #16476 the (jruby) RBE keeps giving errors. These additions are to minimize
IOErrorduring shutdown.💥 What does this PR do?
@closingvariable to stop doing things if we want to shut down#abort_on_exceptionandreport_on_exceptionto false and specifying what we want in the rescue🔧 Implementation Notes
ngl, I'm not certain we need all of this, but jruby is very picky.I spent a lot of time consulting/arguing with several LLMs about this and how it fits into where I think we need to go, and learning a lot more about threads and sockets and async than I actually want to know. I'm much more confident about where this sits now.
The main issue is that propagating errors to the main thread isn't a good idea. If the main thread is in an unrelated ruby block when it is interrupted, that block could intercept the standard error unintentionally. There are ways we can manage propagating errors, but this way can cause issues.
Of note Playwright does not throw uncaught exceptions in Python or Java; (just JS where it seems like it's the only option).
This code checks if it is a bidi implementation and just logs the error, which I think is what we want the default to be right now.
I'm keeping existing devtools behavior as-is for backwards compatibility and flagging it as deprecated. Is that too much? Should we just move to the safer logging-only behavior right away?
We can do something safer when we move to a slightly different implementation that gives users more control over desired behavior.
🔄 Types of changes
PR Type
Bug fix
Description
Add synchronization with mutex around callback and message operations
Expand connection error handling to include EBADF, IOError, EOFError
Implement graceful shutdown with @closing flag and thread joining
Improve error logging and exception handling in socket listener
Reorder quit operations to close bidi before HTTP connection
Diagram Walkthrough
File Walkthrough
websocket_connection.rb
Add mutex synchronization and graceful shutdown handlingrb/lib/selenium/webdriver/common/websocket_connection.rb
for comprehensive error handling
synchronization
thread.exit
callback failures
CONNECTION_ERRORS
handshake
of socket.eof?
report_on_exception to false with explicit error logging
bidi_bridge.rb
Reorder quit to close bidi before parent quitrb/lib/selenium/webdriver/remote/bidi_bridge.rb
gracefully
bridge.rb
Expand quit errors and improve close handlingrb/lib/selenium/webdriver/remote/bridge.rb
rescue