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

Retry on connection failures #292

Merged
merged 6 commits into from
Jun 2, 2024

Conversation

bakonyiferenc
Copy link
Contributor

Fixes (#252)

  • Implemented improved error handling and retry mechanism to handle transient network failures such as connection resets.
  • Added exponential backoff strategy for retry attempts
  • Ensured graceful handling of connection-related errors like ClientConnectorError, ClientOSError, and ServerDisconnectedError

Fixes (iMicknl#252)

- Implemented improved error handling and retry mechanism to handle transient network failures such as connection resets.
- Added exponential backoff strategy for retry attempts
- Ensured graceful handling of connection-related errors like ClientConnectorError, ClientOSError, and ServerDisconnectedError
Copy link
Owner

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

Looks good! Would you be willing to leverage backoff instead of your own retry implementation?

I am using this for some other libraries and it is very flexible and easy to use.
https://github.com/iMicknl/python-overkiz-api/blob/3f9758380fdee9a298957ffe21d02940292f1934/pyoverkiz/client.py#L394

@bakonyiferenc
Copy link
Contributor Author

Sure! Please review the modified implementation.

Copy link
Owner

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

Thanks!

ClientOSError,
ServerDisconnectedError,
) as exception:
raise ConnectionError(str(exception)) from exception
Copy link
Owner

Choose a reason for hiding this comment

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

Why would we want to raise a more general ConnectionError exception, instead of the underlying exception?

See https://docs.aiohttp.org/en/v3.8.2/client_reference.html#hierarchy-of-exceptions. You can actually already use ClientError to catch broader exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two main reasons in my mind:

  1. To hide the internals of the API. If we ever change the underlying aiohttp library, aiohttp specific exceptions like ClientConnectorError or ClientError will be a source of issues later.
  2. Raising a single type of built-in exception (ConnectionError) simplifies the error handling logic. Consumers of the API don't need to worry about the specific connection errors that might occur; they can simply catch ConnectionError and handle it appropriately.

@iMicknl
Copy link
Owner

iMicknl commented Jun 2, 2024

Happy to merge! Would you be able to run poetry lock to fix the CI/CD?

@iMicknl iMicknl merged commit f57f5e6 into iMicknl:main Jun 2, 2024
4 checks passed
@iMicknl iMicknl added the enhancement New feature or request label Jun 2, 2024
@bakonyiferenc bakonyiferenc deleted the retry-connection-failures branch June 2, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants