Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upIdentify errors which indicate the transaction should be retried #1095
Comments
This comment has been minimized.
|
Sounds good. What other ORMs do this and can we learn from their API design? |
This comment has been minimized.
|
I'm not aware of any which make these categorisations explicit. However, with most ORMs/database connectors you can simply catch an exception of the appropriate type. The closest might be sqlalchemy, which has an "invalidates_connection" flag which is set for exceptions wrapping database errors: http://docs.sqlalchemy.org/en/latest/core/exceptions.html#sqlalchemy.exc.DBAPIError For detecting deadlocks, etc. you have to look at the inner exception raised by the database connector, or just catch all |
This comment has been minimized.
|
I don't think it makes sense for Diesel to arbitrarily retry anything by default, but I'd be fine with adding a |
This comment has been minimized.
|
I think changing |
This comment has been minimized.
|
Update on this: We didn't change the signature of |
This comment has been minimized.
|
This is also very important when using a connection pool: currently Something like an For example, if rollback fails on a transaction, then the connection really needs to be marked as broken, or else it will be returned to the connection pool! |
This comment has been minimized.
|
@Diggsey It is completely valid to return |
This comment has been minimized.
|
@sgrif I am worried about transactions not being closed properly, ie. if a connection is returned to the pool with an open transaction, then Another issue is if the "transaction rollback" call fails, then even if the A better option would be to immediately close the connection any time an unrecoverable error occurs: then If this is combined with the changes to |
Diggsey commentedAug 13, 2017
It's very important to be able to distinguish "transient" errors, such as the transaction being rolled back due to a deadlock, or because of a serialization conflict, from other errors, such as constraint violations, malformed queries, etc. where retrying makes no sense.
I think there should probably be three categories:
The first kind is the most important, since these errors are expected to happen as part of normal database usage.