@@ -328,12 +328,15 @@ where
328
328
}
329
329
}
330
330
331
- /// If the transaction fails to commit due to a `SerializationFailure` or a
332
- /// `ReadOnlyTransaction` a rollback will be attempted. If the rollback succeeds,
333
- /// the original error will be returned, otherwise the error generated by the rollback
334
- /// will be returned. In the second case the connection will be considered broken
335
- /// as it contains a uncommitted unabortable open transaction.
331
+ /// If the transaction fails to commit due to a `ReadOnlyTransaction` a rollback will be
332
+ /// attempted. If the rollback succeeds, the original error will be returned, otherwise
333
+ /// the error generated by the rollback will be returned. In the second case the connection
334
+ /// will be considered broken as it contains a uncommitted unabortable open transaction.
335
+ /// If the transaction fails to commit due to a `SerializationFailure` no rollback will
336
+ /// be performed, because it already closes the transaction.
336
337
async fn commit_transaction ( conn : & mut Conn ) -> QueryResult < ( ) > {
338
+ use diesel:: result:: DatabaseErrorKind :: SerializationFailure ;
339
+
337
340
let transaction_state = Self :: get_transaction_state ( conn) ?;
338
341
let transaction_depth = transaction_state. transaction_depth ( ) ;
339
342
let ( commit_sql, committing_top_level) = match transaction_depth {
@@ -358,7 +361,7 @@ where
358
361
let is_broken = conn. transaction_state ( ) . is_broken . clone ( ) ;
359
362
360
363
match Self :: critical_transaction_block ( & is_broken, conn. batch_execute ( & commit_sql) ) . await {
361
- Ok ( ( ) ) => {
364
+ a @ ( Ok ( ( ) ) | Err ( Error :: DatabaseError ( SerializationFailure , _ ) ) ) => {
362
365
match Self :: get_transaction_state ( conn) ?
363
366
. change_transaction_depth ( TransactionDepthChange :: DecreaseDepth )
364
367
{
@@ -369,7 +372,7 @@ where
369
372
}
370
373
Err ( e) => return Err ( e) ,
371
374
}
372
- Ok ( ( ) )
375
+ a
373
376
}
374
377
Err ( commit_error) => {
375
378
if let TransactionManagerStatus :: Valid ( ValidTransactionManagerStatus {
0 commit comments