Skip to content

Commit

Permalink
Avoid infinite loop if save point does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Mooney authored and ribasushi committed Mar 30, 2016
1 parent 66c817d commit f5f0cb1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Peter Valdemar Mørch <peter@morch.com>
peter: Peter Collingbourne <peter@pcc.me.uk>
phaylon: Robert Sedlacek <phaylon@dunkelheit.at>
plu: Johannes Plunien <plu@cpan.org>
pmooney: Paul Mooney <paul.mooney@net-a-porter.com>
Possum: Daniel LeWarne <possum@cpan.org>
pplu: Jose Luis Martinez <jlmartinez@capside.com>
quicksilver: Jules Bean <jules@jellybean.co.uk>
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Revision history for DBIx::Class
create()/populate()
- Remove spurious exception warping in ::Replicated::execute_reliably
(RT#113339)
- Fix infinite loop on ->svp_release("nonexistent_savepoint") (GH#97)
- Fix spurious ROLLBACK statements when a TxnScopeGuard fails a commit
of a transaction with deferred FK checks: a guard is now inactivated
immediately before the commit is attempted (RT#107159)
Expand Down
11 changes: 7 additions & 4 deletions lib/DBIx/Class/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,15 @@ sub svp_release {

if (defined $name) {
my @stack = @{ $self->savepoints };
my $svp;
my $svp = '';

do { $svp = pop @stack } until $svp eq $name;
while( $svp ne $name ) {

$self->throw_exception ("Savepoint '$name' does not exist")
unless $svp;
$self->throw_exception ("Savepoint '$name' does not exist")
unless @stack;

$svp = pop @stack;
}

$self->savepoints(\@stack); # put back what's left
}
Expand Down
12 changes: 12 additions & 0 deletions t/storage/savepoints.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Test::More;
use Test::Exception;
use DBIx::Class::Optional::Dependencies;
use DBIx::Class::_Util qw(sigwarn_silencer scope_guard);
use Scalar::Util 'weaken';

use DBICTest;

Expand Down Expand Up @@ -240,6 +241,17 @@ for ('', keys %$env2optdep) { SKIP: {
# make sure a fresh txn will work after above
$schema->storage->txn_do(sub { ok "noop" } );

### Make sure non-existend savepoint release doesn't infloop itself
{
weaken( my $s = $schema );

throws_ok {
$s->storage->txn_do(sub { $s->svp_release('wibble') })
} qr/Savepoint 'wibble' does not exist/,
"Calling svp_release on a non-existant savepoint throws expected error"
;
}

### cleanupz
$schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
}}
Expand Down

0 comments on commit f5f0cb1

Please sign in to comment.