Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/hatch_rest_api/util_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

_LOGGER = logging.getLogger(__name__)

# Seconds to wait for the MQTT connection to establish before giving up.
# Prevents thread pool workers from blocking indefinitely when the Hatch
# cloud is unreachable in ways that don't fail fast (e.g. hung TCP).
MQTT_CONNECT_TIMEOUT = 30

io.init_logging(io.LogLevel.NoLogs, "stderr")


Expand Down Expand Up @@ -93,7 +98,9 @@ async def get_rest_devices(
)
try:
connect_future = await loop.run_in_executor(None, mqtt_connection.connect)
await loop.run_in_executor(None, connect_future.result)
await loop.run_in_executor(
None, partial(connect_future.result, MQTT_CONNECT_TIMEOUT)
)
_LOGGER.debug("mqtt connection connected")
except Exception as e:
_LOGGER.error(f"MQTT connection failed with exception {e}")
Expand Down