Skip to content

Commit ad7a16d

Browse files
committed
Do not return connections to the pool if an error occurs in ROLLBACK
1 parent 01efa4c commit ad7a16d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/conn/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,9 @@ impl Conn {
12301230
/// Requires that `self.inner.tx_status != TxStatus::None`
12311231
pub(crate) async fn rollback_transaction(&mut self) -> Result<()> {
12321232
debug_assert_ne!(self.inner.tx_status, TxStatus::None);
1233+
self.query_drop("ROLLBACK").await?;
12331234
self.inner.tx_status = TxStatus::None;
1234-
self.query_drop("ROLLBACK").await
1235+
Ok(())
12351236
}
12361237

12371238
/// Returns `true` if `SERVER_MORE_RESULTS_EXISTS` flag is contained
@@ -1282,23 +1283,22 @@ impl Conn {
12821283
/// The purpose of this function, is to cleanup the connection while returning it to a [`Pool`].
12831284
async fn cleanup_for_pool(mut self) -> Result<Self> {
12841285
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+
}
12871297
} 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?;
12891300
} else {
12901301
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-
}
13021302
}
13031303
}
13041304
Ok(self)

0 commit comments

Comments
 (0)