diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2015-06-13 20:27:51 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2015-06-13 20:27:51 +0100 |
commit | a4cde71b1a09721ef2183495ba7e536ba88c2d8b (patch) | |
tree | dfc2f937f6d6e1b77c2c572e6a880155125c6404 /infra/dgit-repos-policy-debian | |
parent | 523f605a62b7f559108b8b7301a88bfaaeb6d4e8 (diff) |
Infra: dgit-repos-policy-debian: Fix db retry loop
Diffstat (limited to 'infra/dgit-repos-policy-debian')
-rwxr-xr-x | infra/dgit-repos-policy-debian | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/infra/dgit-repos-policy-debian b/infra/dgit-repos-policy-debian index e665a63..5d843a0 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 $!; |