From: Ian Jackson Date: Sat, 13 Jun 2015 19:27:51 +0000 (+0100) Subject: Infra: dgit-repos-policy-debian: Fix db retry loop X-Git-Tag: debian/0.30~85 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=a4cde71b1a09721ef2183495ba7e536ba88c2d8b;ds=sidebyside Infra: dgit-repos-policy-debian: Fix db retry loop --- diff --git a/infra/dgit-repos-policy-debian b/infra/dgit-repos-policy-debian index e665a636..5d843a06 100755 --- a/infra/dgit-repos-policy-debian +++ b/infra/dgit-repos-policy-debian @@ -452,21 +452,34 @@ if (!$fn) { my $sleepy=0; my $rcode; +my $db_busy_exception= 'Debian::Dgit::Policy::Debian::DB_BUSY'; + +my @orgargv = @ARGV; + for (;;) { - poldb_setup(poldb_path($repos)); - $stderr = ''; + @ARGV = @orgargv; + eval { + poldb_setup(poldb_path($repos)); + $stderr = ''; + + $poldbh->{HandleError} = sub { + return 0 unless $poldbh->err == 5; # SQLITE_BUSY, not in .pm :-( + die bless { }, $db_busy_exception; + }; - $rcode = $fn->(); - die unless defined $rcode; + $rcode = $fn->(); + die unless defined $rcode; - eval { $poldbh->commit; }; + $poldbh->commit; + }; last unless length $@; + die $@ unless ref $@ eq $db_busy_exception; die if $sleepy >= 20; - print STDERR "[policy database busy, retrying]\n"; - sleep ++$sleepy; + $sleepy++; + print STDERR "[policy database busy, retrying (${sleepy}s)]\n"; - $poldbh->rollback; + eval { $poldbh->rollback; }; } print STDERR $stderr or die $!;