cjaliaga/home-assistant-aquarea

RuntimeError: Session is closed

zurada opened this issue · 3 comments

Hi I use the latest version and the preview version I can't use anymore the integration, reloading / reinstalling the integration does not help.
What to do?
Logs:

Logger: custom_components.aquarea.coordinator
Source: helpers/update_coordinator.py:290
Integration: Aquarea Smart Cloud (documentation, issues)
First occurred: 2 grudnia 2023 18:21:08 (860 occurrences)
Last logged: 13:48:31

Unexpected error fetching aquarea-(Removed personal data) data: Session is closed
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/aquarea/coordinator.py", line 57, in _async_update_data
self._device = await self._client.get_device(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aioaquarea/core.py", line 52, in _wrap
response = await fn(client, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aioaquarea/core.py", line 356, in get_device
device_info, await self.get_device_status(device_info.long_id), self
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aioaquarea/core.py", line 52, in _wrap
response = await fn(client, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aioaquarea/core.py", line 290, in get_device_status
response = await self.request(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aioaquarea/core.py", line 157, in request
resp = await self._sess.request(method, AQUAREA_SERVICE_BASE + url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 400, in _request
raise RuntimeError("Session is closed")
RuntimeError: Session is closed

It seems the session was closed (the aiohttp session, which is handled by Home Assistant) so the device is not able to refresh the data. I would really like to understand how and why Home Assistant is closing the session, it should be alive while the integration is loaded... Maybe there's some race condition that I'm not aware or able to replicate.

I'll try to add tons of DEBUG logging so it can be enabled and traced... When I finish with the consumption sensors I'll focus more on these errors to see if we can either find the root cause or at least try to see if we can mitigate them...

Hi,

When I reconfigured DNS IP of HA which was 8.8.8.8 and changed it to my local IP gateway - started working smoothly without any issue,

So the "session closed" means no internet connection. I think that can be improved if no internet connection is encountered, wdyt?

Thanks for the great work!!!!!

This is great information! Some users has reported the same session closed that was resolved when either improving connectivity or the wifi signal to the adapter... I'll see if I can reproduce this on a local environment, maybe we need to better handle reconnections...