rroller / dahua

Dahua Camera and Doorbell Home Assistant Integration
MIT License
382 stars 73 forks source link

Possible memory leak with Python 3.11.2 and Debian Bookworm on RPI with HASS Core installation #311

Open altserg opened 10 months ago

altserg commented 10 months ago

Hi all,

I'm using HASS Core on RPI, and I'm moving to the latest Debian OS version. I have noticed that with Python 3.11.2 (also with Python 3.11 manually compiled on previous RPI OS version), the memory usage raises very quickly when Dahua integration is enabled. Refer to attached memory usage log with peaks at the end corresponding to enablement of Dahua integration and HASS restart

image

I'm wondering if anyone else has noticed something similar, and I would appreciate any help in debugging the issue - how to track all memory allocations in Dahua component ? Or maybe it's something with asyncio that goes wrong ?

altserg commented 10 months ago

Looks like the issue is related to https://github.com/aio-libs/aiohttp/issues/7252 Flag enable_cleanup_closed=True in iohttp.TCPConnector. When I removed the flag in init.py, the memory consumption is not increasing so rapidly. I'm testing now, will report the result. However, if this works, should some Python version check and quick be implemented in init.py ? Note that in the linked issue people are saying that the fix should be implemented in Python 3.11.4, I had the memory leak in self-compiled later Python 3.11 versions. Debian bookworm has Python 3.11.2, so the quirk has to be implemented there anyway. This is what HASS implements aiohttp_client.py:ENABLE_CLEANUP_CLOSED = not (3, 11, 1) <= sys.version_info < (3, 11, 4) aiohttp_client.py: enable_cleanup_closed=ENABLE_CLEANUP_CLOSED,

altserg commented 10 months ago

So far so good with enable_cleanup_closed=False image