Skip to content

Retry on connection failures#292

Merged
iMicknl merged 6 commits intoiMicknl:mainfrom
bakonyiferenc:retry-connection-failures
Jun 2, 2024
Merged

Retry on connection failures#292
iMicknl merged 6 commits intoiMicknl:mainfrom
bakonyiferenc:retry-connection-failures

Conversation

@bakonyiferenc
Copy link
Copy Markdown
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
@bakonyiferenc bakonyiferenc requested a review from iMicknl as a code owner April 3, 2024 16:29
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Sure! Please review the modified implementation.

@bakonyiferenc bakonyiferenc force-pushed the retry-connection-failures branch from c3da94b to 9eb018f Compare April 18, 2024 17:36
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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
jsongerber pushed a commit to jsongerber/python-sagemcom-api that referenced this pull request Nov 8, 2024
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`
bakonyiferenc added a commit to bakonyiferenc/python-sagemcom-api that referenced this pull request Dec 16, 2025
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`
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