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.
This commit is contained in:
Stefan Agner 2025-05-13 12:37:35 +02:00 committed by GitHub
parent 154aeaee87
commit da0ae75e8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
connector = aiohttp.TCPConnector(loop=self.loop, resolver=resolver)
session = aiohttp.ClientSession(