From 796e7215a167f36d0b950631c3b1e44fa47fec07 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 24 Aug 2021 22:49:24 +0000 Subject: imap+nntp: die loudly if ->mm or ->over disappear While the WWW front-end can gracefully handle ->mm and ->over disappearing (in most cases), IMAP+NNTP front-ends are completely dependent on these and failed mysteriously when they go missing after startup. These will hopefully make issues like what Konstantin encountered more obvious: Link: https://public-inbox.org/meta/20210824204855.ejspej4z7r2rpu63@nitro.local/ --- lib/PublicInbox/Inbox.pm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/PublicInbox/Inbox.pm') diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index b94ffdb0..df140cac 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -8,6 +8,7 @@ use PublicInbox::Git; use PublicInbox::MID qw(mid2path); use PublicInbox::Eml; use List::Util qw(max); +use Carp qw(croak); # Long-running "git-cat-file --batch" processes won't notice # unlinked packs, so we need to restart those processes occasionally. @@ -168,8 +169,8 @@ sub max_git_epoch { } sub mm { - my ($self) = @_; - $self->{mm} ||= eval { + my ($self, $req) = @_; + $self->{mm} //= eval { require PublicInbox::Msgmap; my $dir = $self->{inboxdir}; if ($self->version >= 2) { @@ -177,7 +178,7 @@ sub mm { } else { PublicInbox::Msgmap->new($dir); } - }; + } // ($req ? croak("E: $@") : undef); } sub search { @@ -195,19 +196,19 @@ sub search { sub isrch { $_[0]->{isrch} // search($_[0]) } sub over { - $_[0]->{over} //= eval { - my $srch = $_[0]->{search} //= do { - _cleanup_later($_[0]); + my ($self, $req) = @_; + $self->{over} //= eval { + my $srch = $self->{search} //= do { + _cleanup_later($self); require PublicInbox::Search; - PublicInbox::Search->new($_[0]); + PublicInbox::Search->new($self); }; my $over = PublicInbox::Over->new("$srch->{xpfx}/over.sqlite3"); $over->dbh; # may fail $over; - }; + } // ($req ? croak("E: $@") : undef); } - sub try_cat { my ($path) = @_; open(my $fh, '<', $path) or return ''; -- cgit v1.2.3-24-ge0c7