Skip to content

Commit e4ce576

Browse files
committed
Fix a bug in how we handle serialization errors
This commit fixes a bug in how we handle serialization errors with the postgres backend and transactions. It turns out that we never update the transaction manager state for `batch_execute` calls, which in turn are used for executing the transaction SQL itself. That could lead to situations in which we don't roll back the transaction, but in which we should have done that. Fixes #241
1 parent 7d45634 commit e4ce576

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/pg/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ impl SimpleAsyncConnection for AsyncPgConnection {
146146
.batch_execute(query)
147147
.map_err(ErrorHelper)
148148
.map_err(Into::into);
149+
149150
let r = drive_future(connection_future, batch_execute).await;
151+
let r = {
152+
let mut transaction_manager = self.transaction_state.lock().await;
153+
update_transaction_manager_status(r, &mut transaction_manager)
154+
};
150155
self.record_instrumentation(InstrumentationEvent::finish_query(
151156
&StrQueryHelper::new(query),
152157
r.as_ref().err(),

src/transaction_manager.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,8 @@ where
381381
..
382382
}) = conn.transaction_state().status
383383
{
384-
match Self::critical_transaction_block(
385-
&is_broken,
386-
Self::rollback_transaction(conn),
387-
)
388-
.await
389-
{
384+
// rollback_transaction handles the critical block internally on its own
385+
match Self::rollback_transaction(conn).await {
390386
Ok(()) => {}
391387
Err(rollback_error) => {
392388
conn.transaction_state().status.set_in_error();

tests/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod instrumentation;
1111
mod pooling;
1212
#[cfg(feature = "async-connection-wrapper")]
1313
mod sync_wrapper;
14+
mod transactions;
1415
mod type_check;
1516

1617
async fn transaction_test<C: AsyncConnection<Backend = TestBackend>>(

0 commit comments

Comments
 (0)