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
This commit is contained in:
Kornel 2018-07-27 17:17:30 +01:00
parent 1e29cf4a0f
commit 2487b18db0

View File

@ -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."),