Merge pull request #241 from jaredj/prune-lock

Don't leave DB locked after pruning empty greylist
This commit is contained in:
Matt Simerson 2015-03-05 21:06:13 -08:00
commit 19650063e6
2 changed files with 8 additions and 2 deletions

View File

@ -502,7 +502,7 @@ sub prune_db {
my @to_delete; my @to_delete;
my $greylist = {}; my $greylist = {};
my @keys = $self->db->get_keys or return; my @keys = $self->db->get_keys or return $self->db->unlock;
@$greylist{ @keys } = ( $self->db->mget(@keys) ); @$greylist{ @keys } = ( $self->db->mget(@keys) );
for my $key ( @keys ) { for my $key ( @keys ) {
my ($ts) = split /:/, delete $greylist->{$key}; my ($ts) = split /:/, delete $greylist->{$key};
@ -510,7 +510,7 @@ sub prune_db {
next if $age < $self->{_args}{white_timeout}; next if $age < $self->{_args}{white_timeout};
push @to_delete, $key; push @to_delete, $key;
} }
return if ! @to_delete; return $self->db->unlock if ! @to_delete;
my $pruned = $self->db->delete(@to_delete); my $pruned = $self->db->delete(@to_delete);
$self->db->unlock; $self->db->unlock;
$self->log(LOGINFO, "pruned $pruned of $count DB entries"); $self->log(LOGINFO, "pruned $pruned of $count DB entries");

View File

@ -264,6 +264,12 @@ sub test_prune_db {
is( $self->allkeys, '', is( $self->allkeys, '',
'prune_db() expires all remaining keys 37 days later' ); 'prune_db() expires all remaining keys 37 days later' );
} }
# Ensure prune_db does not leave the database locked after doing nothing
delete $self->{db};
$self->db( class => 'Qpsmtpd::DB::File::DBM', dir => 't/tmp' );
$self->prune_db;
$self->prune_db;
ok(1, "We won't get this far if prune_db leaves the database locked");
} }
sub allkeys { sub allkeys {