From e76b6a9048d49111f2cdeaef3117df4ccf0e5c65 Mon Sep 17 00:00:00 2001 From: Jared Johnson Date: Wed, 21 Jan 2015 16:43:23 -0600 Subject: [PATCH] Fix consistency problems with DBM store Destroy the AnyDBM-tied hash after untying Google's wisdom seems to indicate that leaving the AnyDBM-tied hash around after untying it was causing data to not flush to the DBM file... or something. At any rate the regression test added here confirms inconsistency when using multiple instances which is fixed by destroying the AnyDBM-tied hash after untying. --- lib/Qpsmtpd/DB/File/DBM.pm | 1 + t/qpsmtpd-db-file-dbm.t | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/Qpsmtpd/DB/File/DBM.pm b/lib/Qpsmtpd/DB/File/DBM.pm index 914aeed..1892833 100644 --- a/lib/Qpsmtpd/DB/File/DBM.pm +++ b/lib/Qpsmtpd/DB/File/DBM.pm @@ -93,6 +93,7 @@ sub unlock { my ( $self ) = @_; close $self->{lock}; untie $self->{tied}; + delete $self->{tied}; } sub get { diff --git a/t/qpsmtpd-db-file-dbm.t b/t/qpsmtpd-db-file-dbm.t index c43aba2..b9871ac 100644 --- a/t/qpsmtpd-db-file-dbm.t +++ b/t/qpsmtpd-db-file-dbm.t @@ -16,6 +16,7 @@ __delete(); __get_keys(); __size(); __flush(); +__untie_gotcha(); done_testing(); @@ -78,3 +79,17 @@ sub __flush { $db->unlock; } +sub __untie_gotcha { + # Regression test for 'gotcha' with untying hash that never goes away + $db->lock; + $db->flush; + $db->set( cut => 'itout' ); + $db->unlock; + my $db2 = Qpsmtpd::DB::File::DBM->new( name => 'testing' ); + $db2->lock; + is( $db2->get('cut'), 'itout', + 'get() in second db handle reads key set in first handle' ); + $db2->unlock; + $db->flush; + $db2->flush; +}