Skip to content

Commit da0ae75

Browse files
authored
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.
1 parent 154aeae commit da0ae75

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

supervisor/coresys.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import TYPE_CHECKING, Any, Self, TypeVar
1414

1515
import aiohttp
16+
from pycares import AresError
1617

1718
from .config import CoreConfig
1819
from .const import (
@@ -121,13 +122,17 @@ async def init_websession(self) -> None:
121122
if self._websession:
122123
await self._websession.close()
123124

124-
resolver = aiohttp.AsyncResolver()
125+
try:
126+
resolver = aiohttp.AsyncResolver(loop=self.loop)
127+
# pylint: disable=protected-access
128+
_LOGGER.debug(
129+
"Initializing ClientSession with AsyncResolver. Using nameservers %s",
130+
resolver._resolver.nameservers,
131+
)
132+
except AresError as err:
133+
_LOGGER.exception("Unable to initialize async DNS resolver: %s", err)
134+
resolver = aiohttp.ThreadedResolver(loop=self.loop)
125135

126-
# pylint: disable=protected-access
127-
_LOGGER.debug(
128-
"Initializing ClientSession with AsyncResolver. Using nameservers %s",
129-
resolver._resolver.nameservers,
130-
)
131136
connector = aiohttp.TCPConnector(loop=self.loop, resolver=resolver)
132137

133138
session = aiohttp.ClientSession(

0 commit comments

Comments
 (0)