From 13cfdad6ab07de4511cd129c7ed7c6ac58ccb4d3 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Wed, 22 Oct 2014 23:12:39 +0200 Subject: [PATCH] Don't rollback when TxnScopeGuard dtor is run twice Modules like Plack::Middleware::StackTrace save a reference to the guard object when a (nested) rollback exception is thrown during destruction resulting in the destructor being called twice. Inactivate the guard after the first rollback. --- lib/DBIx/Class/Storage/TxnScopeGuard.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/DBIx/Class/Storage/TxnScopeGuard.pm b/lib/DBIx/Class/Storage/TxnScopeGuard.pm index 7cb373777..9d102650b 100644 --- a/lib/DBIx/Class/Storage/TxnScopeGuard.pm +++ b/lib/DBIx/Class/Storage/TxnScopeGuard.pm @@ -106,6 +106,12 @@ sub DESTROY { } } + # Modules like Plack::Middleware::StackTrace save a reference to the + # guard object when a (nested) rollback exception is thrown resulting + # in the destructor being called twice. Inactivating the guard protects + # against trying to rollback a second time. + $self->{inactivated} = 1; + $@ = $exception; }