about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--lib/PublicInbox/Inbox.pm11
-rw-r--r--lib/PublicInbox/Mbox.pm6
-rw-r--r--lib/PublicInbox/SearchView.pm4
3 files changed, 13 insertions, 8 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 267be4e3..55e546e1 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -191,14 +191,19 @@ sub mm {
         };
 }
 
-sub search ($;$) {
-        my ($self, $over_only) = @_;
+sub search ($;$$) {
+        my ($self, $over_only, $ctx) = @_;
         my $srch = $self->{search} ||= eval {
                 _cleanup_later($self);
                 require PublicInbox::Search;
                 PublicInbox::Search->new($self);
         };
-        ($over_only || eval { $srch->xdb }) ? $srch : undef;
+        ($over_only || eval { $srch->xdb }) ? $srch : do {
+                $ctx and $ctx->{env}->{'psgi.errors'}->print(<<EOF);
+`$self->{name}' search went away unexpectedly
+EOF
+                undef;
+        };
 }
 
 sub over ($) {
diff --git a/lib/PublicInbox/Mbox.pm b/lib/PublicInbox/Mbox.pm
index fc83a893..a83c0356 100644
--- a/lib/PublicInbox/Mbox.pm
+++ b/lib/PublicInbox/Mbox.pm
@@ -205,8 +205,8 @@ sub mbox_all_ids {
 
 sub results_cb {
         my ($ctx) = @_;
+        my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
         my $mset = $ctx->{mset};
-        my $srch = $ctx->{srch};
         while (1) {
                 while (my $mi = (($mset->items)[$ctx->{iter}++])) {
                         my $smsg = PublicInbox::Smsg::from_mitem($mi,
@@ -227,8 +227,8 @@ sub mbox_all {
 
         return mbox_all_ids($ctx) if $query eq '';
         my $qopts = $ctx->{qopts} = { mset => 2 };
-        my $srch = $ctx->{srch} = $ctx->{-inbox}->search or
-                return PublicInbox::WWW::need($ctx, 'Search');;
+        my $srch = $ctx->{-inbox}->search or
+                return PublicInbox::WWW::need($ctx, 'Search');
         my $mset = $ctx->{mset} = $srch->query($query, $qopts);
         $qopts->{offset} = $mset->size or
                         return [404, [qw(Content-Type text/plain)],
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 84c04c6c..5d77469e 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -321,7 +321,6 @@ sub adump {
         my ($cb, $mset, $q, $ctx) = @_;
         $ctx->{items} = [ $mset->items ];
         $ctx->{search_query} = $q; # used by WwwAtomStream::atom_header
-        $ctx->{srch} = $ctx->{-inbox}->search;
         PublicInbox::WwwAtomStream->response($ctx, 200, \&adump_i);
 }
 
@@ -329,8 +328,9 @@ sub adump {
 sub adump_i {
         my ($ctx) = @_;
         while (my $mi = shift @{$ctx->{items}}) {
+                my $srch = $ctx->{-inbox}->search(undef, $ctx) or return;
                 my $smsg = eval {
-                        PublicInbox::Smsg::from_mitem($mi, $ctx->{srch});
+                        PublicInbox::Smsg::from_mitem($mi, $srch);
                 } or next;
                 return $smsg;
         }