twrecked / hass-aarlo

Asynchronous Arlo Component for Home Assistant
GNU Lesser General Public License v3.0
394 stars 78 forks source link

HA reporting mqtt timeout, possible memory leak #1007

Open mcvicthor opened 1 week ago

mcvicthor commented 1 week ago

Recently I noticed that HA might have a memory leak as memory usage grows every day until depletion. Looked into what can cause it and noticed a constant logging in homeassistant.log:

2024-10-30 06:59:09.579 ERROR (ArloEventStream) [pyaarlo] mqtt-error=TimeoutError Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/pyaarlo/backend.py", line 583, in _mqtt_main self._event_client.connect(self._arlo.cfg.mqtt_host, port=self._arlo.cfg.mqtt_port, keepalive=60) File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 914, in connect return self.reconnect() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1044, in reconnect sock = self._create_socket_connection() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/socket.py", line 853, in create_connection raise exceptions[0] File "/usr/local/lib/python3.12/socket.py", line 838, in create_connection sock.connect(sa) TimeoutError: timed out

I have tried both sse and mqtt but error comes up regardless.

mcvicthor commented 5 days ago

I have disabled the integration for testing. Memory stable at 21% usage for over a day. I have re-enabled the integration and since this morning (6 hrs) slowly creeping up, at 30% and growing.

configuration.yaml:

aarlo: username: xxxxxx password: xxxxx tfa_source: push tfa_type: PUSH refresh_devices_every: 2 stream_timeout: 120 reconnect_every: 90 backend: sse

mqtt_hostname_check: False

mqtt_host: mqtt-cluster-z1.arloxcld.com

Error in homeassitant.log (every 30 seconds):

2024-10-31 15:12:18.231 ERROR (ArloEventStream) [pyaarlo] mqtt-error=TimeoutError Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/pyaarlo/backend.py", line 583, in _mqtt_main self._event_client.connect(self._arlo.cfg.mqtt_host, port=self._arlo.cfg.mqtt_port, keepalive=60) File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 914, in connect return self.reconnect() ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1044, in reconnect sock = self._create_socket_connection() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/socket.py", line 853, in create_connection raise exceptions[0] File "/usr/local/lib/python3.12/socket.py", line 838, in create_connection sock.connect(sa) TimeoutError: timed out

twrecked commented 1 day ago

Which version are you on?

mcvicthor commented 1 day ago

Running version 2024.10.4 of HA and latest of the integration. I downgraded HA to an earlier version I had (about 2 months old) and the issue is still there

twrecked commented 1 day ago

I'm looking into the memory leak but it's looking like it might be related to the library the MQTT client uses. The code inside Aarlo that uses it is very simple and sets the variable holding the MQTT client to None after the exception. I'll keep looking.

I'm asking which version because changing aarlo in configuration.yaml won't make any difference. Version 0.8+ uses an aarlo.yaml file to add extra config. What does that contain?

mcvicthor commented 1 day ago

oh, that makes sense why i did not see a difference :)

aarlo.yaml:

version: 1 aarlo: reconnect_every: 90 backend: mqtt mqtt_hostname_check: false mqtt_host: mqtt-cluster-z1.arloxcld.com

twrecked commented 1 day ago

You can now configure a lot of the settings on the integration page but Arlo has a lot of configuration settings so I moved some of the least frequently used to that file.

You can try the auto setting for the back end - see here. And If you end up with sse it's going to mask the problem.

mcvicthor commented 1 day ago

I just switched to auto and I don't see the error being thrown in the logs. Will keep an eye on the memory usage and update the following days.

Thanks for all the help and the work on the integration