mirror of
https://github.com/home-assistant/supervisor.git
synced 2026-10-02 02:08:48 +01:00
aiohttp caches built middleware chains in a module-level, process-wide functools.lru_cache(maxsize=1024) keyed on (handler, apps tuple). Our test suite builds a fresh RestAPI/web.Application (bound to a fresh CoreSys) for nearly every test, so almost every test call is a cache miss that inserts a new, never-reused entry - each one pinning an entire CoreSys object graph (docker mocks, D-Bus proxies, aiohttp routes, etc.) in memory until 1024 stale entries force LRU eviction. Over a full tests/api run this causes steady, effectively unbounded memory growth that reliably OOMs. Add an autouse fixture that clears aiohttp's internal _cached_build_middleware cache after every test. Verified with the full tests/api suite (1097 tests): now completes in ~2:15 with peak RSS ~490MB, versus growing past several GB and crashing before this change.