fix: add timeout to mqtt connect to avoid indefinite hang - #69
Conversation
connect_future.result was awaited with no timeout, so an unreachable or half-open connection to the Hatch cloud blocked the executor thread and the calling coroutine forever. Follows the same approach as the MQTT_TIMEOUT added to ShadowClientSubscriberMixin in dahlb#60. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KUv54T1tjc6TJYCsUXyPE2
|
I independently observed the connect-side failure today on a separate production Home Assistant instance using hatch_rest_api 1.32.0. During repeated Core startups, A bounded Please add regression tests covering:
It would also be useful to confirm that a timed-out native connect attempt is cleaned up or cannot accumulate across retries. Companion Home Assistant event-loop fix: dahlb/ha_hatch#320. |
Summary
get_rest_deviceswaits on the MQTT connect future with no timeout:If the Hatch cloud is unreachable in a way that doesn't fail fast (hung TCP, half-open connection during an outage),
connect_future.resultblocks its executor thread and the awaiting coroutine forever. In the ha_hatch integration this manifests as config entry setup hanging indefinitely during Hatch cloud outages.This applies the same fix as #60 did for the shadow client operations: a bounded wait (30 s) that raises
concurrent.futures.TimeoutError, which propagates through the existingexceptblock inget_rest_devicesso callers can retry with backoff.Context
During a Hatch cloud outage on 2026-07-24 this hang (together with a companion bug in ha_hatch, PR incoming there) repeatedly locked up a Home Assistant instance from ~4:41 AM until the integration was disabled.
Testing
pytest tests/— 23 passed🤖 Generated with Claude Code
https://claude.ai/code/session_01KUv54T1tjc6TJYCsUXyPE2