Add 15sec request timeout to all API calls, fixing indefinite hangs #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
This PR adds a 15 second timeout to all API requests to Leviton. As per the
requests
lib docs, a call may hang indefinitely without a timeout. A timeout will improve the reliability of always-on applications of the decora_wifi lib.Motivation
I use this library as part of homeassistant. I have found very rarely (once every 2 months or so) that the decora_wifi integration can break. Attaching a python debugger, I find a worker thread stuck indefinitely in the following stacktrace:
With this PR, I believe the flaky
call_api()
would timeout instead of getting stuck, and the following homeassistant update loop would hopefully succeed.Implementation
15 seconds should surely be enough for any call. I looked if I could attach a timeout to the
requests.Session
, but that appears to not be possible.