@@ -146,6 +146,11 @@ pub struct AnsiTransactionManager {
146
146
// See https://github.com/weiznich/diesel_async/issues/198 for
147
147
// details
148
148
pub ( crate ) is_broken : Arc < AtomicBool > ,
149
+ // this boolean flag tracks whether we are currently in this process
150
+ // of trying to commit the transaction. this is useful because if we
151
+ // are and we get a serialization failure, we might not want to attempt
152
+ // a rollback up the chain.
153
+ pub ( crate ) is_commit : bool ,
149
154
}
150
155
151
156
impl AnsiTransactionManager {
@@ -355,9 +360,18 @@ where
355
360
conn. instrumentation ( )
356
361
. on_connection_event ( InstrumentationEvent :: commit_transaction ( depth) ) ;
357
362
358
- let is_broken = conn. transaction_state ( ) . is_broken . clone ( ) ;
363
+ let is_broken = {
364
+ let transaction_state = conn. transaction_state ( ) ;
365
+ transaction_state. is_commit = true ;
366
+ transaction_state. is_broken . clone ( )
367
+ } ;
368
+
369
+ let res =
370
+ Self :: critical_transaction_block ( & is_broken, conn. batch_execute ( & commit_sql) ) . await ;
371
+
372
+ conn. transaction_state ( ) . is_commit = false ;
359
373
360
- match Self :: critical_transaction_block ( & is_broken , conn . batch_execute ( & commit_sql ) ) . await {
374
+ match res {
361
375
Ok ( ( ) ) => {
362
376
match Self :: get_transaction_state ( conn) ?
363
377
. change_transaction_depth ( TransactionDepthChange :: DecreaseDepth )
@@ -392,6 +406,9 @@ where
392
406
} ) ;
393
407
}
394
408
}
409
+ } else {
410
+ Self :: get_transaction_state ( conn) ?
411
+ . change_transaction_depth ( TransactionDepthChange :: DecreaseDepth ) ?;
395
412
}
396
413
Err ( commit_error)
397
414
}
0 commit comments