@@ -1230,8 +1230,9 @@ impl Conn {
1230
1230
/// Requires that `self.inner.tx_status != TxStatus::None`
1231
1231
pub ( crate ) async fn rollback_transaction ( & mut self ) -> Result < ( ) > {
1232
1232
debug_assert_ne ! ( self . inner. tx_status, TxStatus :: None ) ;
1233
+ self . query_drop ( "ROLLBACK" ) . await ?;
1233
1234
self . inner . tx_status = TxStatus :: None ;
1234
- self . query_drop ( "ROLLBACK" ) . await
1235
+ Ok ( ( ) )
1235
1236
}
1236
1237
1237
1238
/// Returns `true` if `SERVER_MORE_RESULTS_EXISTS` flag is contained
@@ -1282,23 +1283,22 @@ impl Conn {
1282
1283
/// The purpose of this function, is to cleanup the connection while returning it to a [`Pool`].
1283
1284
async fn cleanup_for_pool ( mut self ) -> Result < Self > {
1284
1285
loop {
1285
- let result = if self . has_pending_result ( ) {
1286
- self . drop_result ( ) . await
1286
+ if self . has_pending_result ( ) {
1287
+ // The connection was dropped and we assume that it was dropped intentionally,
1288
+ // so we'll ignore non-fatal errors during cleanup (also there is no direct caller
1289
+ // to return this error to).
1290
+ if let Err ( err) = self . drop_result ( ) . await {
1291
+ if err. is_fatal ( ) {
1292
+ // This means that connection is completely broken
1293
+ // and shouldn't return to a pool.
1294
+ return Err ( err) ;
1295
+ }
1296
+ }
1287
1297
} else if self . inner . tx_status != TxStatus :: None {
1288
- self . rollback_transaction ( ) . await
1298
+ // If an error occurs during rollback, don't reuse the connection.
1299
+ self . rollback_transaction ( ) . await ?;
1289
1300
} else {
1290
1301
break ;
1291
- } ;
1292
-
1293
- // The connection was dropped and we assume that it was dropped intentionally,
1294
- // so we'll ignore non-fatal errors during cleanup (also there is no direct caller
1295
- // to return this error to).
1296
- if let Err ( err) = result {
1297
- if err. is_fatal ( ) {
1298
- // This means that connection is completely broken
1299
- // and shouldn't return to a pool.
1300
- return Err ( err) ;
1301
- }
1302
1302
}
1303
1303
}
1304
1304
Ok ( self )
0 commit comments