From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 57BB41FA18 for ; Thu, 14 Jan 2021 07:06:28 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/14] lei: reduce live FD references in wq child Date: Wed, 13 Jan 2021 19:06:18 -1200 Message-Id: <20210114070627.18195-6-e@80x24.org> In-Reply-To: <20210114070627.18195-1-e@80x24.org> References: <20210114070627.18195-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can shrink the @TO_CLOSE_ATFORK_CHILD array by two elements, at least. I may be possible to eliminate this array entirely but clobbering $quit doesn't seem to remove references to $eof_w or the $listener socket. --- lib/PublicInbox/LEI.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 7a1df0bb..fd2b722c 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -279,6 +279,7 @@ sub atfork_child_wq { my ($self, $wq) = @_; @$self{qw(0 1 2 sock)} = delete(@$wq{0..3}); %PATH2CFG = (); + $quit = \&CORE::exit; @TO_CLOSE_ATFORK_CHILD = (); (__WARN__ => sub { err($self, @_) }, PIPE => sub { @@ -782,8 +783,8 @@ sub lazy_start { return if $pid; $0 = "lei-daemon $path"; local %PATH2CFG; - local @TO_CLOSE_ATFORK_CHILD = ($l, $eof_r, $eof_w); - $_->blocking(0) for ($l, $eof_r, $eof_w); + local @TO_CLOSE_ATFORK_CHILD = ($l, $eof_w); + $l->blocking(0); $l = PublicInbox::Listener->new($l, \&accept_dispatch, $l); my $exit_code; local $quit = sub { @@ -795,6 +796,7 @@ sub lazy_start { PublicInbox::DS->SetLoopTimeout(1000); }; PublicInbox::EOFpipe->new($eof_r, \&noop, undef); + undef $eof_r; my $sig = { CHLD => \&PublicInbox::DS::enqueue_reap, QUIT => $quit, @@ -806,9 +808,10 @@ sub lazy_start { }; my $sigfd = PublicInbox::Sigfd->new($sig, SFD_NONBLOCK); local @SIG{keys %$sig} = values(%$sig) unless $sigfd; + undef $sig; local $SIG{PIPE} = 'IGNORE'; if ($sigfd) { # TODO: use inotify/kqueue to detect unlinked sockets - push @TO_CLOSE_ATFORK_CHILD, $sigfd->{sock}; + undef $sigfd; PublicInbox::DS->SetLoopTimeout(5000); } else { # wake up every second to accept signals if we don't