-
Notifications
You must be signed in to change notification settings - Fork 64
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
Lost connections are not retried #989
Comments
I've also noticed this in my apps, but haven't been able to manually replicate to narrow it down. I guess I thought that crystal-db just did the retry stuff internally, but your patch makes sense. I'm not sure what edge cases we'd have to consider here, but I'm down to give it a shot. |
From Brian Cardiff's comments here and here, it does until you do an explicit call to
I have a PR that passes all existing tests, but I'm not sure how to add a test case for this one. I should probably wait for a few more days to see if the issue does not recur in my staging apps to be really sure. |
Ah, ok. It looks like your patch is probably good then. Oh, what happens if you don't have any |
The default retry of In all cases, the app should work OK if connection is never lost; retry kicks in only after all connections in the pool are broken. I've just rerun the I've also not received any error report from staging yet, so seems we're good. I'm going to wait for 1 more day. |
That's great news! Thanks for investigating this. |
avram/src/avram/database.cr
Lines 188 to 201 in 0b9797b
In the lines of code above,
Avram::Database#with_connection
helper checks out a connection and checks it in after use. But if the connection is lost/broken, the query is never retried, leading toDB::ConnectionLost
errors:This affects multiple apps of mine in a staging environment. I use a serverless database provide who suspends the server after a period of inactivity (it boots up again after a connection attempt is made). This breaks the connection if no interaction is made to the database for a while.
I've applied a patch and tested for about 3 days now; no errors yet. I used to get those errors almost daily from both the app server and Mel workers attempting to reach the database. Here is a trace from Mel:
My patch looks like this:
Or maybe it's something else I've missed?
The text was updated successfully, but these errors were encountered: