about summary refs log tree commit homepage
path: root/lib/PublicInbox/LEI.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-04 03:49:13 +0000
committerEric Wong <e@80x24.org>2023-10-04 17:46:29 +0000
commit1cbad18d329faad67c85f4d56f79afc80a2c80c4 (patch)
treedf318d5cdd79d90f9ff89a624d4e35d555d6ffea /lib/PublicInbox/LEI.pm
parent8768d434ebf67c25f1584ad7ad213dca7dc12a05 (diff)
downloadpublic-inbox-1cbad18d329faad67c85f4d56f79afc80a2c80c4.tar.gz
This will allow us to avoid unblocking signals during
shutdown to simplify our code.
Diffstat (limited to 'lib/PublicInbox/LEI.pm')
-rw-r--r--lib/PublicInbox/LEI.pm13
1 files changed, 12 insertions, 1 deletions
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