]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: close DirIdle (inotify) early at daemon shutdown
authorEric Wong <e@80x24.org>
Wed, 4 Oct 2023 03:49:17 +0000 (03:49 +0000)
committerEric Wong <e@80x24.org>
Wed, 4 Oct 2023 17:46:33 +0000 (17:46 +0000)
We don't want FS activity to delay lei-daemon shutdown.

lib/PublicInbox/DirIdle.pm
lib/PublicInbox/LEI.pm

index af99811c7da539bbdf6278d6748c9560e98759e0..de6f229b5b46bd1af6616ed9cd92c5660a688f2b 100644 (file)
@@ -68,10 +68,16 @@ sub rm_watches {
        }
 }
 
+sub close {
+       my ($self) = @_;
+       delete $self->{cb};
+       $self->SUPER::close; # if using real kevent/inotify
+}
+
 sub event_step {
        my ($self) = @_;
-       my $cb = $self->{cb};
-       local $PublicInbox::DS::in_loop = 0; # waitpid() synchronously
+       my $cb = $self->{cb} or return;
+       local $PublicInbox::DS::in_loop = 0; # waitpid() synchronously (FIXME)
        eval {
                my @events = $self->{inot}->read; # Linux::Inotify2->read
                $cb->($_) for @events;
@@ -83,7 +89,7 @@ sub force_close {
        my ($self) = @_;
        my $inot = delete $self->{inot} // return;
        if ($inot->can('fh')) { # Linux::Inotify2 2.3+
-               close($inot->fh) or warn "CLOSE ERROR: $!";
+               CORE::close($inot->fh) or warn "CLOSE ERROR: $!";
        } elsif ($inot->isa('Linux::Inotify2')) {
                require PublicInbox::LI2Wrap;
                PublicInbox::LI2Wrap::wrapclose($inot);
index 74a7f5b92288e5286334ede71ac955c1ef7f8d55..8362800dad40cf8b1c8421f95e40f1ac94ff4aec 100644 (file)
@@ -1285,8 +1285,11 @@ sub can_stay_alive { # PublicInbox::DS::post_loop_do cb
        }
        return 1 if defined($$path);
        my $n = PublicInbox::DS::close_non_busy() or do {
+               eval 'PublicInbox::LeiNoteEvent::flush_task()';
                # drop stores only if no clients
                for my $cfg (values %PATH2CFG) {
+                       my $lne = delete($cfg->{-lei_note_event});
+                       $lne->wq_close if $lne;
                        my $sto = delete($cfg->{-lei_store}) // next;
                        eval { $sto->wq_io_do('done') };
                        warn "E: $@ (dropping store for $cfg->{-f})" if $@;
@@ -1346,6 +1349,8 @@ sub lazy_start {
                my (undef, $eof_p) = PublicInbox::PktOp->pair;
                sub {
                        $exit_code //= eval("POSIX::SIG$_[0] + 128") if @_;
+                       $dir_idle->close if $dir_idle; # EPOLL_CTL_DEL
+                       $dir_idle = undef; # let RC take care of it
                        eval 'PublicInbox::LeiNoteEvent::flush_task()';
                        my $lis = $pil or exit($exit_code // 0);
                        # closing eof_p triggers \&noop wakeup