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

fix: reconnect when send message fails #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Mar 31, 2025

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When an error is raised when sending a message through the socket it just gets logged

What is the new behavior?

Handle the raised error when sending a message and initiate the reconnect flow.

Additional context

Add any other context or screenshots.

@grdsdev grdsdev requested a review from Copilot March 31, 2025 17:02
Copy link

@Copilot Copilot AI left a 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 addresses a reconnection issue when sending messages fails by updating the connection attribute usage and error handling. Key changes include:

  • Switching from the public ws_connection attribute to the internal _ws_connection in both connection logic and tests.
  • Introducing a new test case to validate reconnection behavior after a simulated connection failure.
  • Updating the pyproject.toml dev dependency configuration.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/test_connection.py Updated tests to reference _ws_connection and added reconnection test case
realtime/_async/client.py Replaced ws_connection with _ws_connection and adjusted error handling
pyproject.toml Reorganized dev dependency configuration under a new dependency group
Comments suppressed due to low confidence (1)

tests/test_connection.py:262

  • [nitpick] The test is directly accessing the protected attribute '_ws_connection'. Consider using a public interface (e.g., is_connected) or a dedicated getter to reduce coupling to internal implementation details.
initial_ws = socket._ws_connection

)

try:
await self._ws_connection.send(message)
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

In the send_message function, errors during message sending are caught and handled with _on_connect_error, but the caller is not informed of the failure. Consider propagating the exception after handling so that the failure is not silently suppressed.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@@ -17,18 +17,15 @@ python-dateutil = "^2.8.1"
typing-extensions = "^4.12.2"
aiohttp = "^3.11.14"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

The new dev dependency group only includes a subset of the dependencies previously defined. Please verify if the removal of dependencies like pytest, python-dotenv, pytest-asyncio, and coveralls is intentional.

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@grdsdev grdsdev marked this pull request as ready for review March 31, 2025 17:06
@grdsdev grdsdev requested a review from silentworks March 31, 2025 17:06
@coveralls
Copy link

coveralls commented Mar 31, 2025

Pull Request Test Coverage Report for Build 14177115261

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+4.8%) to 83.8%

Totals Coverage Status
Change from base Build 14145452679: 4.8%
Covered Lines: 688
Relevant Lines: 821

💛 - Coveralls

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.

3 participants