Avoid churning zeroconf instances in the host resolver when created in the reconnect logic (#729)
This commit is contained in:
parent
991214ef52
commit
aded2d28b5
|
@ -58,6 +58,7 @@ async def _async_zeroconf_get_service_info(
|
||||||
timeout: float,
|
timeout: float,
|
||||||
) -> AsyncServiceInfo:
|
) -> AsyncServiceInfo:
|
||||||
# Use or create zeroconf instance, ensure it's an AsyncZeroconf
|
# Use or create zeroconf instance, ensure it's an AsyncZeroconf
|
||||||
|
had_instance = zeroconf_manager.has_instance
|
||||||
try:
|
try:
|
||||||
zc = zeroconf_manager.get_async_zeroconf().zeroconf
|
zc = zeroconf_manager.get_async_zeroconf().zeroconf
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
@ -73,7 +74,8 @@ async def _async_zeroconf_get_service_info(
|
||||||
f"Error resolving mDNS {service_name} via mDNS: {exc}"
|
f"Error resolving mDNS {service_name} via mDNS: {exc}"
|
||||||
) from exc
|
) from exc
|
||||||
finally:
|
finally:
|
||||||
await zeroconf_manager.async_close()
|
if not had_instance:
|
||||||
|
await zeroconf_manager.async_close()
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,11 @@ class ZeroconfManager:
|
||||||
if zeroconf is not None:
|
if zeroconf is not None:
|
||||||
self.set_instance(zeroconf)
|
self.set_instance(zeroconf)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_instance(self) -> bool:
|
||||||
|
"""Return True if a Zeroconf instance is set."""
|
||||||
|
return self._aiozc is not None
|
||||||
|
|
||||||
def set_instance(self, zc: AsyncZeroconf | Zeroconf) -> None:
|
def set_instance(self, zc: AsyncZeroconf | Zeroconf) -> None:
|
||||||
"""Set the AsyncZeroconf instance."""
|
"""Set the AsyncZeroconf instance."""
|
||||||
if self._aiozc:
|
if self._aiozc:
|
||||||
|
|
Loading…
Reference in New Issue