Skip to content

Retry setup on transient network errors instead of failing permanently - #603

Open
jaypopat wants to merge 1 commit into
albertogeniola:masterfrom
jaypopat:fix/retry-setup-on-transient-network-errors
Open

Retry setup on transient network errors instead of failing permanently#603
jaypopat wants to merge 1 commit into
albertogeniola:masterfrom
jaypopat:fix/retry-setup-on-transient-network-errors

Conversation

@jaypopat

@jaypopat jaypopat commented Aug 24, 2026

Copy link
Copy Markdown

Problem

async_setup_entry converts meross_iot exceptions into ConfigEntryAuthFailed or ConfigEntryNotReady, but transport errors raised by aiohttp are not handled. They propagate out of async_setup_entry, so HomeAssistant marks the entry SETUP_ERROR. That state is never retried, since only ConfigEntryNotReady triggers retry with backoff, so the integration stays down until the user reloads it by hand.

A momentary network hiccup at startup therefore takes the integration offline indefinitely. The usual trigger is HomeAssistant starting before the network is ready, so the first devList call fails on DNS:

ERROR (MainThread) [homeassistant.config_entries] Error setting up entry https://iot.meross.com for meross_cloud
  File "custom_components/meross_cloud/__init__.py", line 420, in async_setup_entry
    await meross_coordinator.initial_setup()
  File "custom_components/meross_cloud/__init__.py", line 144, in initial_setup
  File "custom_components/meross_cloud/__init__.py", line 342, in get_or_test_creds
  File "meross_iot/http_api.py", line 476, in async_list_devices
  File "meross_iot/http_api.py", line 341, in _async_authenticated_post
aiohttp.client_exceptions.ClientConnectorDNSError: Cannot connect to host iotx-eu.meross.com:443 ssl:default [Could not contact DNS servers]

One attempt, zero retries. On my install it sat in SETUP_ERROR for three days after a host reboot with every Meross device unavailable, while other cloud integrations that hit the same blip at the same moment recovered on their own.

#599 reports the same failure with an identical traceback (same lines 420, 144, 342) and ClientConnectorError, which is the WAN-drop variant of the same bug.

Fix

Catch aiohttp.ClientError and asyncio.TimeoutError in initial_setup and async_setup_entry, and raise ConfigEntryNotReady so HomeAssistant retries with backoff.

aiohttp.ClientError is the common ancestor of both reported variants, ClientConnectorDNSError and ClientConnectorError, as well as ClientOSError and ServerTimeoutError.

Authentication handling is unchanged, so bad credentials still stop rather than retry forever.

Testing

Verified against the aiohttp shipped with current HomeAssistant (3.14.3) that all four variants above are caught by aiohttp.ClientError.

Confirmed the recovery path on a live 1.3.12 install: the entry had been in SETUP_ERROR since a reboot three days earlier and came back immediately on a config entry reload, which is what ConfigEntryNotReady would have done automatically.

I did not fault inject a DNS failure against the patched code, as that would have meant deliberately breaking name resolution on a production setup. Happy to add that if you would like it verified that way.

async_setup_entry converts meross_iot exceptions into ConfigEntryNotReady
or ConfigEntryAuthFailed, but transport errors raised by aiohttp are not
handled. They propagate out of async_setup_entry, so HomeAssistant marks
the entry SETUP_ERROR and never retries it. The integration then stays
down until the user reloads it by hand.

This triggers whenever the cloud is briefly unreachable at setup time,
most often when HomeAssistant starts before the network is ready and the
first devList call fails on DNS.

Catch aiohttp.ClientError and asyncio.TimeoutError in initial_setup and
async_setup_entry and raise ConfigEntryNotReady, so setup is retried with
backoff. aiohttp.ClientError covers both reported variants,
ClientConnectorDNSError and ClientConnectorError.

Fixes albertogeniola#599
@jaypopat
jaypopat force-pushed the fix/retry-setup-on-transient-network-errors branch from c7e6836 to 1bd9e3d Compare August 24, 2026 19:36
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.

1 participant