-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection pool unreliable? #196
Comments
As long as you are not checking out connections explicitly the pool should be able to recover from temporary outages. Sample in mysql https://crystal-lang.org/reference/database/connection_pool.html Maybe an exception with the wrong type is raised and the connection loss is not detected. But you snippets looks good and i would expect to be resilient. |
Possibly it's postgres specific? I couldn't find a way to make my above snippet resilient - it always breaks |
Yeah, I've encountered similar errors with postgres as well, but never did any deeper investigation. So maybe it's an issue in |
also finding this an issue working with GCP's hosted postgres compatible database and new connections take upwards of 2 seconds to connect meaning we really need to rely on the pool. Also seeing the pool not recovering from DB outages - we work around that using health checks, but it's not optimal |
From a cursory look at the code, the connection pool does not automatically retry a lost connection. To ensure a lost connection is retried, db.retry do
db.query #...
end Otherwise, all the Perhaps |
The I haven't validated if something is off with pg in this regard though. |
Oh, I must have missed that, then. I get Here's a trace, if that helps:
I suspect the app attempts the first connection, fails and raises the error without a retry. I have tried various connection params to no avail. Currently its They are Lucky apps, and it seems Avram does an explicit checkout here: I don't see a retry there. Could that be it, or am I missing something? |
Currently
DB::Database
does not recover from temporaryconnection failures. It does not seem to evict broken connections
from the pool but continues to attempt to use them.
This means just a single brief outage will
leave the pool in a permanently broken state.
The only way to recover from connection failures appears to
be to discard the entire
DB::Database
instance and create a new pool.Is this a bug or am I using it wrong? 🤔
Test-case:
Just leave the above running and while it runs
restart your local postgres server.
Regardless of what settings you choose, you will see the following output:
The text was updated successfully, but these errors were encountered: