]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: drop stores explicitly at daemon shutdown
authorEric Wong <e@80x24.org>
Wed, 4 Oct 2023 03:49:13 +0000 (03:49 +0000)
committerEric Wong <e@80x24.org>
Wed, 4 Oct 2023 17:46:29 +0000 (17:46 +0000)
This will allow us to avoid unblocking signals during
shutdown to simplify our code.

lib/PublicInbox/DS.pm
lib/PublicInbox/LEI.pm

index 142122a8652bde295b7eeae0d82e05419e553a09..c476311b9e1a92a89cf5f94ddeeb74b35c9450f0 100644 (file)
@@ -38,10 +38,9 @@ our @EXPORT_OK = qw(now msg_more awaitpid add_timer add_uniq_timer);
 
 my %Stack;
 my $nextq; # queue for next_tick
-my $AWAIT_PIDS; # pid => [ $callback, @args ]
 my $reap_armed;
 my $ToClose; # sockets to close when event loop is done
-our (
+our ($AWAIT_PIDS, # pid => [ $callback, @args ]
      %DescriptorMap,             # fd (num) -> PublicInbox::DS object
      $Poller, # global Select, Epoll, DSPoll, or DSKQXS ref
 
index 10c08b905f1a92bb010251bc16946cb22fde9069..368eee2665755143d23e59e6689589565f8f9acb 100644 (file)
@@ -1271,6 +1271,15 @@ sub dir_idle_handler ($) { # PublicInbox::DirIdle callback
        }
 }
 
+sub drop_all_stores () {
+       for my $cfg (values %PATH2CFG) {
+               my $sto = delete($cfg->{-lei_store}) // next;
+               eval { $sto->wq_io_do('done') };
+               warn "E: $@ (dropping store for $cfg->{-f})" if $@;
+               $sto->wq_close;
+       }
+}
+
 # lei(1) calls this when it can't connect
 sub lazy_start {
        my ($path, $errno, $narg) = @_;
@@ -1367,7 +1376,9 @@ sub lazy_start {
                                $s->close;
                        }
                }
-               $n; # true: continue, false: stop
+               drop_all_stores() if !$n; # drop stores only if no clients
+               # returns true: continue, false: stop
+               $n + scalar(keys(%$PublicInbox::DS::AWAIT_PIDS));
        });
 
        # STDIN was redirected to /dev/null above, closing STDERR and