From da0ae75e8e732eb823807269471d17df5d1b020c Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 13 May 2025 12:37:35 +0200 Subject: [PATCH] Fallback to threaded resolver in case AsyncResolver fails (#5882) In case the c-ares based AsyncResolver fails to initialize, let's fallback to the threaded resolver. This would have helped for aiodns 3.3.0 issue when clients were unable to allocate more inotify watches. This is fixed in aiodns 3.4.0, but we should still fallback to the threaded resolver as a precautionary measure. --- supervisor/coresys.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/supervisor/coresys.py b/supervisor/coresys.py index 4847a7f1a..7ddda4ce9 100644 --- a/supervisor/coresys.py +++ b/supervisor/coresys.py @@ -13,6 +13,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, Self, TypeVar import aiohttp +from pycares import AresError from .config import CoreConfig from .const import ( @@ -121,13 +122,17 @@ class CoreSys: if self._websession: await self._websession.close() - resolver = aiohttp.AsyncResolver() + try: + resolver = aiohttp.AsyncResolver(loop=self.loop) + # pylint: disable=protected-access + _LOGGER.debug( + "Initializing ClientSession with AsyncResolver. Using nameservers %s", + resolver._resolver.nameservers, + ) + except AresError as err: + _LOGGER.exception("Unable to initialize async DNS resolver: %s", err) + resolver = aiohttp.ThreadedResolver(loop=self.loop) - # pylint: disable=protected-access - _LOGGER.debug( - "Initializing ClientSession with AsyncResolver. Using nameservers %s", - resolver._resolver.nameservers, - ) connector = aiohttp.TCPConnector(loop=self.loop, resolver=resolver) session = aiohttp.ClientSession(