From 2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 31 Jan 2021 22:28:24 -1000 Subject: sharedkv: lock and explicitly disconnect {dbh} It may be possible for updates or changes to be uncommitted until disconnect, so we'll use flock() as we do elsewhere to avoid the polling retry behavior of SQLite. We also need to clear CachedKids before disconnecting to to avoid warnings like: ->disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) --- lib/PublicInbox/SharedKV.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/SharedKV.pm') diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm index f5d09cc1..77df0fb4 100644 --- a/lib/PublicInbox/SharedKV.pm +++ b/lib/PublicInbox/SharedKV.pm @@ -143,9 +143,17 @@ SELECT COUNT(k) FROM kv $sth->fetchrow_array; } +sub dbh_release { + my ($self, $lock) = @_; + my $dbh = delete $self->{dbh} or return; + $lock //= $self->lock_for_scope; # may be needed for WAL + %{$dbh->{CachedKids}} = (); # cleanup prepare_cached + $dbh->disconnect; +} + sub DESTROY { my ($self) = @_; - delete $self->{dbh}; + dbh_release($self); my $dir = delete $self->{"tmp$$.$self"} or return; my $tries = 0; do { -- cgit v1.2.3-24-ge0c7