Improve db_pools init: do not crash if DB unavailable during startup (sqlx) #2932
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2931
Why?
When using
Pool::connect[_with]
, sqlx attempts to connect to the givendatabase immediately, and the fairing will fail if there are any
problems in that attempt (beyond obvious configuration problems that are
found before hitting the network), e.g.:
There are a few pros and cons to this approach:
Pros:
Cons:
normally crash a server if one becomes unavailable after startup,
so why should it prevent a server from starting at all? See
[deadpool's justification]{https://docs.rs/deadpool} for not crashing.
errors as your edit-test loop now involves restarting an application
rather than refreshing a page or trying a request again.
deployments" in standard deployment scenarios.
database recovery, requiring reboots to follow a functioning database
or applications not to be restarted at certain times
Effect of change
The sqlx backend now behaves like the deadpool backend: no connection
issues are surfaced during startup. You will not see them until you
attempt to get a connection from the pool. That means rocket will launch
and you can find problems like these in smoke tests.