Skip to content

Conversation

@ledhed2222
Copy link
Collaborator

High Level Overview of Change

quick improvement to examples of async websocket code

Context of Change

Type of Change

  • 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 not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Tests (You added tests for code that already exists, or your new feature included in this PR)
  • Documentation Updates
  • Release

Did you update CHANGELOG.md?

  • Yes
  • No, this change does not impact library users

Test Plan

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 27, 2025

Walkthrough

The changes narrow exception handling in an async websocket client by replacing broad except clauses with targeted handlers. KeyboardInterrupt is explicitly re-raised for cancellation, while other exceptions trigger reconnection logic. A try/finally block ensures listener task cleanup regardless of success or failure.

Changes

Cohort / File(s) Summary
Async WebSocket Client Exception Handling
xrpl/asyncio/clients/async_websocket_client.py
Replaces broad exception handling with targeted except Exception blocks; KeyboardInterrupt explicitly re-raised in supervision loop; subscription block wrapped with try/finally to guarantee listener task cancellation; error/reconnect semantics refined without public API changes

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit's ode to clean exception flows

Broad catches once swallowed all errors whole,
Now KeyboardInterrupt claims its rightful role,
With finally blocks ensuring cleanup's due,
No listener task left in the queue! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes an improvement to async websocket examples, but the actual changes involve replacing broad except clauses with targeted exception handling and improving resource cleanup in async websocket client code—not documentation examples. Revise the title to accurately reflect the actual code changes, such as 'improve exception handling in async websocket client' or 'add explicit KeyboardInterrupt handling in websocket supervision'.
Description check ⚠️ Warning The description is largely incomplete: only the high-level overview contains text ('quick improvement to examples'), while all other required sections (Context of Change, Type of Change checkbox selection, Test Plan) are left blank or unchecked. Complete the description by selecting the appropriate Type of Change checkbox (likely 'Refactor'), providing context explaining the exception handling improvements, and detailing the test plan used to verify the changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
xrpl/asyncio/clients/async_websocket_client.py (1)

196-207: Good addition of cleanup logic with try/finally block.

The try/finally block ensures the listener task is cancelled regardless of how the function exits. This is essential for proper resource management in async code.

Consider awaiting the cancelled task to avoid "Task was destroyed but it is pending" warnings and ensure clean cancellation:

🔎 Proposed enhancement for cleaner task cancellation
                 finally:
                     # whether or not there is an error, cancel the listener
                     listener.cancel()
+                    try:
+                        await listener
+                    except asyncio.CancelledError:
+                        pass
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1464e9e and 6fa321e.

📒 Files selected for processing (1)
  • xrpl/asyncio/clients/async_websocket_client.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-01-15T00:41:02.631Z
Learnt from: ckeshava
Repo: XRPLF/xrpl-py PR: 773
File: tests/integration/reusable_values.py:112-119
Timestamp: 2025-01-15T00:41:02.631Z
Learning: In xrpl-py integration tests, errors during test setup should be allowed to terminate the test suite naturally to aid debugging, rather than being caught and wrapped in custom error handlers. This applies to functions like `sign_and_reliable_submission_async` which already have robust error handling.

Applied to files:

  • xrpl/asyncio/clients/async_websocket_client.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Integration test (3.10)
  • GitHub Check: Integration test (3.9)
  • GitHub Check: Integration test (3.11)
  • GitHub Check: Integration test (3.13)
  • GitHub Check: Integration test (3.14)
  • GitHub Check: Integration test (3.12)
  • GitHub Check: Integration test (3.8)
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
xrpl/asyncio/clients/async_websocket_client.py (1)

139-145: Excellent improvement to exception handling specificity.

Replacing the bare except: with except Exception: is the correct approach. This allows KeyboardInterrupt and other BaseException subclasses to propagate properly, enabling users to cancel the async context with Ctrl-C.

Comment on lines +178 to 183
except KeyboardInterrupt:
# allow crtl-c to actually cancel
raise
except Exception:
# anything else reconnects
print("Lost connection! Reconnecting")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Excellent pattern for supervisor loop with proper cancellation support.

The explicit KeyboardInterrupt handling enables users to cleanly exit the supervisor loop with Ctrl-C, while all other exceptions trigger reconnection. This is the recommended pattern for websocket supervisors.

Minor typo: "crtl-c" → "ctrl-c" on line 179.

🤖 Prompt for AI Agents
In xrpl/asyncio/clients/async_websocket_client.py around lines 178 to 183, there
is a minor typo in the inline comment text: "crtl-c" should be "ctrl-c"; update
the comment to read "allow ctrl-c to actually cancel" (preserve
capitalization/style) so the docstring/comment is correct while leaving the
exception handling logic unchanged.

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.

2 participants