Skip to content

[grid] Accept legacy session-closed event payloads - #17343

Merged
VietND96 merged 1 commit into
trunkfrom
event-data-backward
Apr 14, 2026
Merged

VietND96 merged 1 commit into
trunkfrom
event-data-backward

Conversation

@VietND96

Copy link
Copy Markdown
Member

🔗 Related Issues

Fixes SeleniumHQ/docker-selenium#3110

💥 What does this PR do?

Backward compatibility for Grid session-closed events when the event bus receives the legacy wire format: a bare JSON string session id instead of a SessionClosedData object.

In 4.41.0, listeners in the distributor and session map deserialize session-closed as SessionClosedData. When an older or custom publisher emits the legacy payload, deserialization fails with Expected to read a START_MAP but instead have: STRING, which prevents the listener from processing the event.

🔧 Implementation Notes

💡 Additional Considerations

🔄 Types of changes

  • Cleanup (formatting, renaming)
  • Bug fix (backwards compatible)
  • New feature (non-breaking change which adds functionality and tests!)
  • Breaking change (fix or feature that would cause existing functionality to change)

Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
@qodo-code-review

Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Accept legacy session-closed event payloads for backward compatibility

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Accept legacy session-closed event payloads with bare SessionId strings
• Deserialize legacy wire format to SessionClosedData with QUIT_COMMAND reason
• Add comprehensive tests for backward compatibility handling

Grey Divider

File Changes

1. java/src/org/openqa/selenium/grid/data/SessionClosedData.java 🐞 Bug fix +5/-0

Add legacy session-closed payload deserialization support

• Import JsonType for type checking during deserialization
• Add legacy payload handling in fromJson() method to detect STRING type
• Deserialize bare SessionId strings as SessionClosedData with QUIT_COMMAND reason
• Maintain backward compatibility with older or custom event publishers

java/src/org/openqa/selenium/grid/data/SessionClosedData.java


2. java/test/org/openqa/selenium/grid/data/SessionClosedDataTest.java 🧪 Tests +64/-0

Add tests for legacy session-closed payload handling

• Create new test class for SessionClosedData backward compatibility
• Test deserialization of legacy SessionId string payload format
• Verify event listeners correctly handle legacy session-closed events
• Validate SessionClosedReason defaults to QUIT_COMMAND for legacy payloads

java/test/org/openqa/selenium/grid/data/SessionClosedDataTest.java


3. java/test/org/openqa/selenium/grid/data/BUILD.bazel ⚙️ Configuration changes +1/-0

Add events dependency for test suite

• Add dependency on //java/src/org/openqa/selenium/events for test support
• Enable SessionClosedEvent listener testing in SessionClosedDataTest

java/test/org/openqa/selenium/grid/data/BUILD.bazel


Grey Divider

Qodo Logo

@selenium-ci selenium-ci added B-grid Everything grid and server related C-java Java Bindings B-build Includes scripting, bazel and CI integrations labels Apr 13, 2026
@qodo-code-review

qodo-code-review Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0)   📘 Rule violations (1)   📎 Requirement gaps (0)
📘\ ☼ Reliability (1)

Grey Divider


Remediation recommended

1. Legacy sessionId not validated 📘 ☼
Description
The new legacy JSON STRING payload handling accepts any session id string without validating it is
non-empty/usable, which can allow malformed protocol-derived input to flow deeper and fail later
with less actionable errors.
Code

java/src/org/openqa/selenium/grid/data/SessionClosedData.java[R144-146]

+    if (input.peek() == JsonType.STRING) {
+      return new SessionClosedData(input.read(SessionId.class), SessionClosedReason.QUIT_COMMAND);
+    }
Evidence
PR Compliance ID 15 requires early validation of external/protocol-derived inputs (e.g.,
non-null/non-empty) with clear exceptions. The added legacy branch reads a SessionId from a JSON
string and immediately constructs SessionClosedData without validating the value;
SessionId(String) only enforces non-null, so empty strings can pass through silently.

java/src/org/openqa/selenium/grid/data/SessionClosedData.java[144-146]
java/src/org/openqa/selenium/remote/SessionId.java[37-39]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The legacy `STRING` payload deserialization path for `SessionClosedData` does not validate the protocol-derived session id value (e.g., non-empty), which can let malformed values through and produce harder-to-debug downstream failures.

## Issue Context
The legacy compatibility branch triggers when `input.peek() == JsonType.STRING` and then calls `input.read(SessionId.class)`; `SessionId(String)` only checks for non-null.

## Fix Focus Areas
- java/src/org/openqa/selenium/grid/data/SessionClosedData.java[144-146]
- java/src/org/openqa/selenium/remote/SessionId.java[37-39]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@VietND96
VietND96 merged commit ef0f569 into trunk Apr 14, 2026
57 checks passed
@VietND96
VietND96 deleted the event-data-backward branch April 14, 2026 00:56
This was referenced May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations B-grid Everything grid and server related C-java Java Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Sessions Id not being released

2 participants