Recurrent PostgreSQL Connection Issues – ConnectionDoesNotExistError using asyncpg

Hello, im experiencing recurring connection issues with my PostgreSQL database hosted on Supabase. My application (a Discord bot written in Python) is encountering the following error during database operations:
asyncpg.exceptions.ConnectionDoesNotExistError: connection was closed in the middle of operation

Technical Details:
  • Library: asyncpg (Python)
  • Operation Type: Simple SQL query execution
  • Frequency: Multiple occurrences in the past 6 hours (previously ran for over 4 months without issues)
Error Log:
File "/application/.local/lib/python3.13/site-packages/asyncpg/connection.py", line 352, in execute asyncpg.exceptions.ConnectionDoesNotExistError: connection was closed in the middle of operation

Application Context:
  • The Discord bot has been running 24/7 for over 4 months on a server
  • Connections are created on demand for each operation
  • I am not currently using a connection pool
Questions:
  • Is there a timeout for idle connections on Supabase?
  • Are there any recommended configurations for long-running applications?
  • Would you recommend using connection pooling for this kind of application?
I appreciate any guidance on best practices to restore stable connections.
Was this page helpful?