Better handle RDS restarts (PP-991) #1689
Merged
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.
Description
This adds the
pool_pre_ping
arg to our DB connections. This should let us deal more gracefully with RDS restarts that happen automatically during maintenance windows.See SQL alchemy docs here:
https://docs.sqlalchemy.org/en/14/core/pooling.html#dealing-with-disconnects
This also updates the
ErrorHandler
function to:ProblemError
exceptions, logging them as a warning, and returning the problem detail doc. We should handle these at another level of the stack, but its good to handle them correctly.OperationalError
as warnings. Sincepool_pre_ping
should reduce the number we see, but we will still get some happening when a restart happens in the middle of a transaction.pool_pre_ping
will just make sure the rest of the connection pool doesn't experience the error because its holding on to a old connection.debug
functionality fromErrorHandler
since its correctly flagged as a possible security issue. I think its unexpected to possibly leak stack traces if we were to set debug logging on a production instance. This is better handled by having the stack traces go to log, which they were already.pool_pre_ping
removes the need to kill the entire process when we have a database error. Since the next connection should be refreshed from the connection pool.Motivation and Context
Looking at the top unhandled exceptions in our app in PP-991. I'm seeing this as the second most common, after the exception that is sorted out in #1688.
How Has This Been Tested?
Checklist