mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-19 15:16:33 +00:00
Recreate aiohttp session on connectivity check (#5332)
It seems to actually get a proper connectivity check run, we need a new vanilla ClientSession() object.
This commit is contained in:
parent
9f3767b23d
commit
1504278223
@ -63,7 +63,7 @@ class CoreSys:
|
|||||||
|
|
||||||
# External objects
|
# External objects
|
||||||
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
|
self._loop: asyncio.BaseEventLoop = asyncio.get_running_loop()
|
||||||
self._websession: aiohttp.ClientSession = aiohttp.ClientSession()
|
self._websession = None
|
||||||
|
|
||||||
# Global objects
|
# Global objects
|
||||||
self._config: CoreConfig = CoreConfig()
|
self._config: CoreConfig = CoreConfig()
|
||||||
@ -96,10 +96,8 @@ class CoreSys:
|
|||||||
self._bus: Bus | None = None
|
self._bus: Bus | None = None
|
||||||
self._mounts: MountManager | None = None
|
self._mounts: MountManager | None = None
|
||||||
|
|
||||||
# Set default header for aiohttp
|
# Setup aiohttp session
|
||||||
self._websession._default_headers = MappingProxyType(
|
self.create_websession()
|
||||||
{aiohttp.hdrs.USER_AGENT: SERVER_SOFTWARE}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Task factory attributes
|
# Task factory attributes
|
||||||
self._set_task_context: list[Callable[[Context], Context]] = []
|
self._set_task_context: list[Callable[[Context], Context]] = []
|
||||||
@ -548,6 +546,16 @@ class CoreSys:
|
|||||||
|
|
||||||
return self.loop.run_in_executor(None, funct, *args)
|
return self.loop.run_in_executor(None, funct, *args)
|
||||||
|
|
||||||
|
def create_websession(self) -> None:
|
||||||
|
"""Create a new aiohttp session."""
|
||||||
|
if self._websession:
|
||||||
|
self.create_task(self._websession.close())
|
||||||
|
|
||||||
|
# Create session and set default header for aiohttp
|
||||||
|
self._websession: aiohttp.ClientSession = aiohttp.ClientSession(
|
||||||
|
headers=MappingProxyType({aiohttp.hdrs.USER_AGENT: SERVER_SOFTWARE})
|
||||||
|
)
|
||||||
|
|
||||||
def _create_context(self) -> Context:
|
def _create_context(self) -> Context:
|
||||||
"""Create a new context for a task."""
|
"""Create a new context for a task."""
|
||||||
context = copy_context()
|
context = copy_context()
|
||||||
|
@ -274,6 +274,8 @@ class Supervisor(CoreSysAttributes):
|
|||||||
"https://checkonline.home-assistant.io/online.txt", timeout=timeout
|
"https://checkonline.home-assistant.io/online.txt", timeout=timeout
|
||||||
)
|
)
|
||||||
except (ClientError, TimeoutError):
|
except (ClientError, TimeoutError):
|
||||||
|
# Need to recreate the websession to avoid stale connection checks
|
||||||
|
self.coresys.create_websession()
|
||||||
self.connectivity = False
|
self.connectivity = False
|
||||||
else:
|
else:
|
||||||
self.connectivity = True
|
self.connectivity = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user