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 914511FBCF for ; Wed, 10 Jun 2020 07:06:25 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 34/82] git: move async_cat reference to PublicInbox::Git Date: Wed, 10 Jun 2020 07:04:31 +0000 Message-Id: <20200610070519.18252-35-e@yhbt.net> In-Reply-To: <20200610070519.18252-1-e@yhbt.net> References: <20200610070519.18252-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Trying to avoid a circular reference by relying on $ibx object here makes no sense, since skipping GitCatAsync::close will result in an FD leak, anyways. So keep GitAsyncCat contained to git-only operations, since we'll be using it for Solver in the distant feature. --- lib/PublicInbox/Git.pm | 3 +++ lib/PublicInbox/GitAsyncCat.pm | 14 ++++++++------ lib/PublicInbox/IMAP.pm | 8 +++++--- lib/PublicInbox/Inbox.pm | 3 --- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index b3ae2b812ba..60236afe7bf 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -283,6 +283,9 @@ sub qx { # returns true if there are pending "git cat-file" processes sub cleanup { my ($self) = @_; + if (my $ac = $self->{async_cat}) { + $ac->close; # PublicInbox::GitAsyncCat::close -> EPOLL_CTL_DEL + } cat_async_wait($self); _destroy($self, qw(cat_rbuf in out pid)); _destroy($self, qw(chk_rbuf in_c out_c pid_c err_c)); diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm index 65e16121969..8701e4cfe48 100644 --- a/lib/PublicInbox/GitAsyncCat.pm +++ b/lib/PublicInbox/GitAsyncCat.pm @@ -13,7 +13,7 @@ use strict; use parent qw(PublicInbox::DS Exporter); use fields qw(git); use PublicInbox::Syscall qw(EPOLLIN EPOLLET); -our @EXPORT = qw(git_async_msg); +our @EXPORT = qw(git_async_cat); sub new { my ($class, $git) = @_; @@ -36,14 +36,16 @@ sub event_step { sub close { my ($self) = @_; - delete $self->{git}; + if (my $git = delete $self->{git}) { + delete $git->{async_cat}; # drop circular reference + } $self->SUPER::close; # PublicInbox::DS::close } -sub git_async_msg ($$$$) { - my ($ibx, $smsg, $cb, $arg) = @_; - $ibx->git->cat_async($smsg->{blob}, $cb, $arg); - $ibx->{async_cat} //= new(__PACKAGE__, $ibx->{git}); +sub git_async_cat ($$$$) { + my ($git, $oid, $cb, $arg) = @_; + $git->cat_async($oid, $cb, $arg); + $git->{async_cat} //= new(__PACKAGE__, $git); # circular reference } 1; diff --git a/lib/PublicInbox/IMAP.pm b/lib/PublicInbox/IMAP.pm index 3c32d846508..3815141a15e 100644 --- a/lib/PublicInbox/IMAP.pm +++ b/lib/PublicInbox/IMAP.pm @@ -388,7 +388,7 @@ sub requeue_once ($) { $self->requeue if $new_size == 1; } -sub uid_fetch_cb { # called by git->cat_async via git_async_msg +sub uid_fetch_cb { # called by git->cat_async via git_async_cat my ($bref, $oid, $type, $size, $fetch_m_arg) = @_; my ($self, undef, $ibx, $msgs, undef, $want) = @$fetch_m_arg; my $smsg = shift @$msgs or die 'BUG: no smsg'; @@ -400,6 +400,7 @@ sub uid_fetch_cb { # called by git->cat_async via git_async_msg } else { $smsg->{blob} eq $oid or die "BUG: $smsg->{blob} != $oid"; } + $$bref =~ s/(?[0], \&uid_fetch_cb, \@_); + git_async_cat($ibx->git, $msgs->[0]->{blob}, \&uid_fetch_cb, \@_); } sub cmd_status ($$$;@) { @@ -719,7 +720,8 @@ sub seq_fetch_m { # long_response my $seq = $want->{-seqno}++; my $cur_num = $msgs->[0]->{num}; if ($cur_num == $seq) { # as expected - git_async_msg($ibx, $msgs->[0], \&uid_fetch_cb, \@_); + git_async_cat($ibx->git, $msgs->[0]->{blob}, + \&uid_fetch_cb, \@_); } elsif ($cur_num > $seq) { # send dummy messages until $seq catches up to $cur_num my $smsg = bless { num => $seq, ts => 0 }, 'PublicInbox::Smsg'; diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 407751c3063..b2b0b56fdd3 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -22,9 +22,6 @@ my $CLEANUP = {}; # string(inbox) -> inbox sub git_cleanup ($) { my ($self) = @_; my $git = $self->{git} or return; - if (my $async_cat = delete $self->{async_cat}) { - $async_cat->close; - } $git->cleanup; }