@@ -328,12 +328,15 @@ where
328328 }
329329 }
330330
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.
336337 async fn commit_transaction ( conn : & mut Conn ) -> QueryResult < ( ) > {
338+ use diesel:: result:: DatabaseErrorKind :: SerializationFailure ;
339+
337340 let transaction_state = Self :: get_transaction_state ( conn) ?;
338341 let transaction_depth = transaction_state. transaction_depth ( ) ;
339342 let ( commit_sql, committing_top_level) = match transaction_depth {
@@ -358,7 +361,7 @@ where
358361 let is_broken = conn. transaction_state ( ) . is_broken . clone ( ) ;
359362
360363 match Self :: critical_transaction_block ( & is_broken, conn. batch_execute ( & commit_sql) ) . await {
361- Ok ( ( ) ) => {
364+ a @ ( Ok ( ( ) ) | Err ( Error :: DatabaseError ( SerializationFailure , _ ) ) ) => {
362365 match Self :: get_transaction_state ( conn) ?
363366 . change_transaction_depth ( TransactionDepthChange :: DecreaseDepth )
364367 {
@@ -369,7 +372,7 @@ where
369372 }
370373 Err ( e) => return Err ( e) ,
371374 }
372- Ok ( ( ) )
375+ a
373376 }
374377 Err ( commit_error) => {
375378 if let TransactionManagerStatus :: Valid ( ValidTransactionManagerStatus {
0 commit comments