From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 34BE51F568 for ; Wed, 4 Oct 2023 03:49:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1696391374; bh=xWLxsYXs4iR7XOfd3ezA+sMmN6WtiEM54HP8H8Q2sUU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Si/wHy54327frsFqAGb37b6cpMha1RNg7gHQwwXU4PsM16IYoi/0Z0rFIqQ3SfR1z Ij3YliOQcqvOkcGQguCBO88ZbEptYNLxD0yqXM9Qtn0ZDQimIc3A+56HyBNMVK5Zqk KVoeMSKqp/BcnY/Vl1NdNM/+AyNLzaiVZyS9fhSo= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/21] lei: close DirIdle (inotify) early at daemon shutdown Date: Wed, 4 Oct 2023 03:49:17 +0000 Message-ID: <20231004034933.3343930-6-e@80x24.org> In-Reply-To: <20231004034933.3343930-1-e@80x24.org> References: <20231004034933.3343930-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We don't want FS activity to delay lei-daemon shutdown. --- lib/PublicInbox/DirIdle.pm | 12 +++++++++--- lib/PublicInbox/LEI.pm | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/DirIdle.pm b/lib/PublicInbox/DirIdle.pm index af99811c..de6f229b 100644 --- a/lib/PublicInbox/DirIdle.pm +++ b/lib/PublicInbox/DirIdle.pm @@ -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); diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 74a7f5b9..8362800d 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -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