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

Add 15sec request timeout to all API calls, fixing indefinite hangs #22

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

Conversation

mitchsw
Copy link

@mitchsw mitchsw commented Aug 28, 2023

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:

read (ssl.py:1134)
recv_into (ssl.py:1278)
readinto (socket.py:706)
_update_chunk_length (response.py:758)
read_chunked (response.py:828)
stream (response.py:624)
generate (models.py:816)
content (models.py:899)
send (sessions.py:747)
request (sessions.py:589)
get (sessions.py:602)
call_api (__init__.py:48)
refresh (iot_switch.py:87)
update (homeassistant/components/decora_wifi/light.py:172)
run (thread.py:58)
_worker (thread.py:83)
run (threading.py:975)
_bootstrap_inner (threading.py:1038)
_bootstrap (threading.py:995)

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.

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.

None yet

1 participant