From 2487b18db08af298cbd4e3848d96d11323321da0 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Jul 2018 17:17:30 +0100 Subject: [PATCH] Avoid keeping transactions unexpectedly open If transaction can't be automatically committed, roll it back to prevent transaction staying open past the lifetime of the Transaction object Fixes #366 --- src/transaction.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transaction.rs b/src/transaction.rs index 89628e0..104bac0 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -197,7 +197,7 @@ impl<'conn> Transaction<'conn> { return Ok(()); } match self.drop_behavior() { - DropBehavior::Commit => self.commit_(), + DropBehavior::Commit => self.commit_().or_else(|_| self.rollback_()), DropBehavior::Rollback => self.rollback_(), DropBehavior::Ignore => Ok(()), DropBehavior::Panic => panic!("Transaction dropped unexpectedly."), @@ -310,7 +310,7 @@ impl<'conn> Savepoint<'conn> { return Ok(()); } match self.drop_behavior() { - DropBehavior::Commit => self.commit_(), + DropBehavior::Commit => self.commit_().or_else(|_| self.rollback()), DropBehavior::Rollback => self.rollback(), DropBehavior::Ignore => Ok(()), DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."),