asyncpg icon indicating copy to clipboard operation
asyncpg copied to clipboard

connection error

Open wrobell opened this issue 5 years ago • 3 comments

It is bit hard to figure out, which exceptions I should catch if I want to recover my application from connection errors.

So far

  • OSError - when database is down
  • CannotConnectNowError when PostgreSQL is starting
  • ConnectionDoesNotExistError when connection is removed from connection pool
  • InterfaceError when message contains one of
    • connection has been released back to the pool
    • the underlying connection is closed

It seems I should add one PostgresConnectionError deriving classes as well? Anything else?

wrobell avatar Dec 05 '19 22:12 wrobell

Can you share the code for the error classes you made @wrobell ? I am having the same problem as you are (catching connection errors) and I wonder how you resolved it

fugacityengr avatar Sep 02 '21 11:09 fugacityengr

@fugacityengr Please take a look at catch_conn_error function in https://gitlab.com/n23/n23/-/blob/master/n23/storage/pg/core.py. This logic serves me well for almost two years, now.

wrobell avatar Sep 02 '21 21:09 wrobell

Thank you so much! Helped me a lot

fugacityengr avatar Sep 06 '21 16:09 fugacityengr