Bug #21547
Updated by Peter Amstutz 10 months ago
Certain database errors represent transient errors. We should tell the client to retry the request by returning a 500 internal server error instead of 422 (which is the default behavior).
#<ActiveRecord::Deadlocked: PG::TRDeadlockDetected: ERROR: deadlock detected>
Rationale: The observed deadlocks in Arvados are conflicts between two statements (a lock ordering issue), so unwinding and retrying is a reasonable solution
#<ActiveRecord::StatementInvalid: PG::UnableToSend>
Rationale: It seems this gets thrown when the API server can't connect to the database.
Here's the list of postgres errors known to the PG gem:
https://github.com/ged/ruby-pg/blob/daec80f91b9519509ca1694a231f11a75cb43f7f/ext/errorcodes.def#L598
https://github.com/ged/ruby-pg/blob/daec80f91b9519509ca1694a231f11a75cb43f7f/ext/pg_errors.c#L88
Some other possible Exceptions to retry:
ConnectionBad
ConnectionException
ConnectionDoesNotExist
ConnectionFailure
TooManyConnections
CannotConnectNow
IdleSessionTimeout
ObjectInUse
LockNotAvailable
AdminShutdown
CrashShutdown
(There's a lot of connection related errors and I don't know the difference between them, but I included them all because it seems like those are very likely to be errors that occur through no fault of the client).