Skip to content

Commit 7bbf24c

Browse files
committed
Close DNS resolvers on setup failure and unload
1 parent 6fc0d73 commit 7bbf24c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

homeassistant/components/dnsip/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: DnsIPConfigEntry) -> boo
5757
elif entry.data[CONF_IPV6]:
5858
await resolver_ipv6.query(hostname, "AAAA")
5959
except (TimeoutError, DNSError) as err:
60+
await resolver_ipv4.close()
61+
await resolver_ipv6.close()
6062
raise ConfigEntryNotReady(f"DNS lookup failed for {hostname}: {err}") from err
6163

6264
entry.runtime_data = DnsIPRuntimeData(
@@ -71,7 +73,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: DnsIPConfigEntry) -> boo
7173
async def async_unload_entry(hass: HomeAssistant, entry: DnsIPConfigEntry) -> bool:
7274
"""Unload DNS IP config entry."""
7375

74-
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
76+
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
77+
if unload_ok:
78+
await entry.runtime_data.resolver_ipv4.close()
79+
await entry.runtime_data.resolver_ipv6.close()
80+
return unload_ok
7581

7682

7783
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:

0 commit comments

Comments
 (0)