This will allow us to avoid unblocking signals during
shutdown to simplify our code.
---
 lib/PublicInbox/DS.pm  |  3 +--
 lib/PublicInbox/LEI.pm | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 142122a8..c476311b 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -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
 
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index 10c08b90..368eee26 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -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

Reply via email to