rocket_db_pools: Allow pool creation to succeed even if DB unavailable (sqlx, maybe others) #2931
Open
2 tasks done
Labels
request
Request for new functionality
What's missing?
The
sqlx
driver forrocket_db_pools
currently crashes at startup if your database is offline or if anything else fails -- sslrootcert is invalid/missing, user doesn't exist, password wrong, etc etc. This is sometimes useful in development as you are reminded to start your database if you forgot, but a log would work just as well. In production it is a bad choice.The
deadpool
crate's second-top-billed feature is that pool creation never fails even if the database is unavailable:I'd like that, basically for the reasoning given there. It is needlessly crashy to do so only at startup.
To motivate somewhat more, if you are not convinced:
Ideal Solution
The sqlx implementation of rocket_db_pools' Database trait uses
Pool::connect_with
instead of Pool::connect_lazy_with. You can make a one-line change to switch toconnect_lazy_with
, and make it behave like deadpool.You could also make it configurable, but if people really want their app to crash in this case, they can follow deadpool's advice and add a fairing that tries to make a connection and crashes the app. People writing
.unwrap()
in a fairing is probably easier than making this configurable.Why can't this be implemented outside of Rocket?
It has been implemented outside of rocket. The deadpool backend behaves this way, I presume. But rocket_db_pools does not configure sqlx to do it.
Are there workarounds usable today?
To work around this limitation, you could probably use a custom Database or Pool implementation, but you would need to make your own wrapper type for
sqlx::Pool
in order to get around the fact that rocket_db_pools implements its traits on that. I will probably do this myself for now, if it turns out to be easy I'll post a snippet.Alternative Solutions
No response
Additional Context
No response
System Checks
The text was updated successfully, but these errors were encountered: