Asyncpg pool close hanging and timeout
OS: Debian 10 Buster Python: 3.9 Databases: 0.5.3 Database backend: postgresql/asyncpg
There was an issue with our database and our app was hanging. We received this asyncpg warning:
Pool.close() is taking over 60 seconds to complete. Check if you have any unreleased connections left. Use asyncio.wait_for() to set a timeout for Pool.close().
That warning is raised from asyncpg's Pool.close() method. In line with their suggestion, I'd like to be able to set a timeout for this, or ideally all of the disconnect logic since an asyncpg timeout setting for this does not exist. My current (context manager only) workaround is approximately:
class DatabaseWithTimeout(Database):
async def __aexit__(self, exc_type, exc_value, traceback):
return await asyncio.wait_for(
super().__aexit__(exc_type, exc_value, traceback),
TIMEOUT_SECONDS
)
But it would be nice if Databases had a similar feature built in. I'm happy to make a PR for this if it makes sense.