-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[grid] Fix race condition and improve logging in LocalSessionMap #15370
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
Conversation
PR Reviewer Guide 🔍(Review updated until commit 6f98efc)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
IMHO, this will not fix #15347, will report details later in the original issue. |
It might not fix 15347. However, sometimes I can reproduce with a strict condition, something like
|
Without looking deeper into this i would assume the following might happen:
Are you able to run a patched version of the Hub? If so, just remove the |
@VietND96 could you share the hub logs when this happens? |
This comment was marked as outdated.
This comment was marked as outdated.
Could you share more of the logs, it is allways good to see what happened some time before and concurrently by other sessions. |
I attched full logs for id e33534f26859916b894c37fcb5da30df |
drain-after-session-count
This comment was marked as outdated.
This comment was marked as outdated.
Yes, It should only perform allready outstanding maintenance operations. When reading the caffeine issues, there are alot of 'there is no guarantee for this and that' statements. |
drain-after-session-count
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 fixes a race condition in LocalSessionMap that occurred when multiple Node events (NodeRemovedEvent and NodeRestartedEvent) tried to remove sessions simultaneously, and improves logging for better visibility into session management operations.
Key changes:
- Introduced thread-safe session management using ReentrantReadWriteLock to prevent concurrent modification issues
- Added IndexedSessionMap class with URI-to-SessionId indexing for efficient batch operations
- Enhanced logging to include session IDs, node URIs, and event details for better debugging
java/src/org/openqa/selenium/grid/sessionmap/local/LocalSessionMap.java
Outdated
Show resolved
Hide resolved
java/src/org/openqa/selenium/grid/sessionmap/local/LocalSessionMap.java
Outdated
Show resolved
Hide resolved
java/src/org/openqa/selenium/grid/sessionmap/local/LocalSessionMap.java
Outdated
Show resolved
Hide resolved
java/src/org/openqa/selenium/grid/sessionmap/local/LocalSessionMap.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Viet Nguyen Duc <[email protected]>
Signed-off-by: Viet Nguyen Duc <[email protected]>
/review |
Persistent review updated to latest commit db33027 |
Signed-off-by: Viet Nguyen Duc <[email protected]>
/review |
Persistent review updated to latest commit 0a2f27c |
/review |
Persistent review updated to latest commit 6f98efc |
Signed-off-by: Viet Nguyen Duc <[email protected]>
Ignore qodo review, since IndexedSessionMap is a custom ConcurrentMap implementation that maintains dual indexing for efficient session management in Grid: Key Benefits & Use Cases
|
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Motivation and Context
Reproduce environment:
SE_NODE_MAX_SESSIONS
> 1 andSE_DRAIN_AFTER_SESSION_COUNT
> 1SE_DRAIN_AFTER_SESSION_COUNT
, the same container spawns up again with the same IP assigned, which results in a situation ofNodeRestartedEvent
Fixed race conditions in LocalSessionMap during concurrent node events by implementing thread-safe session management with read-write locks and defensive event handling.
Race Condition Fix
Problem: Concurrent
NodeRemovedEvent
andNodeRestartedEvent
during node shutdowns could cause thread safety issues when multiple events tried to remove the same sessions simultaneously.Solution:
Improve logging of Local Session Map
NodeRemovedEvent
orNodeRestartedEvent
message with the attached event class name triggered and nodeUriTypes of changes
Checklist
PR Type
Bug fix
Description
Replaced
NodeRemovedEvent
withnode.drain()
inNodeServer
shutdown hook.Ensures proper session handling during node shutdown.
Prevents unexpected session removal during server glitches or restarts.
Changes walkthrough 📝
NodeServer.java
Updated NodeServer shutdown hook for graceful shutdown
java/src/org/openqa/selenium/grid/node/httpd/NodeServer.java
NodeRemovedEvent
firing in the shutdown hook.node.drain()
call to handle node draining during shutdown.