MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Memory leak with Pool usage #1024

Open timberkerkvliet opened 1 year ago

timberkerkvliet commented 1 year ago

When we use a Pool, the memory usage of our process keeps increasing slowly with the number of queries. After 1000 queries, it is ~10MB and this increases with the number of queries executed on connections acquired from the pool. This remains after the max_inactive_connection_lifetime has passed with no activity, with explicit garbage collection and even after we close the pool. We can reproduce this with a psutil measurement and observe it in production. When we replace the usage of Pool with our own creation/cleanup of asynpg Connections, the issue dissapears.

Pool created with the following arguments:

asyncpg.create_pool(
    max_inactive_connection_lifetime=300,
    command_timeout=30,
    min_size=0,
    max_size=5
)
elprans commented 1 year ago

Possibly #955?