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

Throttle and retry #3

Merged
merged 2 commits into from
Aug 11, 2020
Merged

Throttle and retry #3

merged 2 commits into from
Aug 11, 2020

Conversation

kit-klein
Copy link
Contributor

When a client is making rapid requests to a device it will often result in ClientError exceptions.

Upon investigation this is occurring for a two reasons.

  1. Multiple async requests can happen in parallel and overload the comms stack of the device. When this happens, the device will start resetting TCP connections - resulting in the exception. To avoid this we now use a semaphore to throttle requests such that they are limited to 3 at once.

  2. aiohttp will reuse sockets for multiple http requests. It appears a race condition can occur where the HA client attempts to send a TCP payload after the device has closed the connection via a FIN. When this happens the device will immediately reset the connection. To handle this each method now performs retries - in testing this completely mitigated the problem.

In addition to the enhancements above I formatted (black) and linted (flake8) the file.

Copy link
Contributor

@heythisisnate heythisisnate left a comment

Choose a reason for hiding this comment

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

this looks good! thanks

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