Replies: 2 comments 2 replies
-
Looking more at the source code, it doesn't seem like passing the For the time being, when ever FastApi is getting a database connection I'm iterating through the It still feels a little clunky, but it seems to be working. If there are better suggestions out there, I'd love to hear them. Thanks! EDIT: Thinking more about this, I think there is probably another case where the approach doesn't work: if some connections in the pool are connected and some are disconnected and then there is enough API activity to warrant the additional pools connecting (I'm sort of assuming that inactive connections that are closed are not re-connected unless they are needed, I haven't looked at the code that closely) then those connection attempts would probably fail. I think the API would then 500 until all connections in the pool were disconnected and then recover. Not ideal. |
Beta Was this translation helpful? Give feedback.
-
@elprans I still don't quite understand if there's a built in way that I can add some exception handling to every fetch operation to trigger getting the secret again in the case where the database credentials have changed. Can either a custom |
Beta Was this translation helpful? Give feedback.
-
I'm using asyncpg as the backend for encode/databases for a FastAPI application.
At application startup I create my database connection pools.
The database connection info is stored in a cloud provider's secrets manager and is rotated on a regular basis.
Right now, when that rotation happens, the application fails without an application restart after credential rotation because we don't currently employ a mechanism for pulling down new credentials in the event of a
aysyncpg.exceptions.InvalidPasswordError
.I'm trying to figure out the best way for handling this credential rotation situation without needing to restart the application.
Is this where I would pass a
setup
coroutine to thecreate_pools()
function?Beta Was this translation helpful? Give feedback.
All reactions