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-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.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0BC281F51E for ; Sat, 1 Oct 2022 18:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1664650371; bh=it7y1EQWjEf//8ltsQMpcu27W44pj8oHslu2vjt3RKs=; h=From:To:Subject:Date:From; b=ERkV3ocVgWkR9CQl2vHY6pxWBzSKfQc6/js3Y4h9ZOWXaN9b8ocLbxzbBVQS6Aoo1 u7l4Cp7Pprm+ABqH6cTJd8nGiN1UHp/yDtsgScLqhr2PcXLz9AMcnp/EGTGjxBPbBT xpGJnGYO6RZl+xZPyDvvb6W+FbfXGHq3XvgjAvZI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] www_stream: use DESTROY to cleanup temporary gits Date: Sat, 1 Oct 2022 15:52:50 -0300 Message-Id: <20221001185250.22577-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Relying on a timer to handle cleanup in f9ac22a4b485 was sub-optimal since the delay could prove expensive under heavy traffic. So rely on ->DESTROY instead since we we no longer hold reference cycles by the time the show_blob callback executes. Fixes: f9ac22a4b485 ("git_async_cat: automatically cleanup temporary gits") --- lib/PublicInbox/GitAsyncCat.pm | 8 -------- lib/PublicInbox/ViewVCS.pm | 1 + lib/PublicInbox/WwwStream.pm | 5 +++++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/GitAsyncCat.pm b/lib/PublicInbox/GitAsyncCat.pm index 2d601542..b32c2fd3 100644 --- a/lib/PublicInbox/GitAsyncCat.pm +++ b/lib/PublicInbox/GitAsyncCat.pm @@ -45,12 +45,6 @@ sub event_step { } } -sub git_tmp_cleanup { - my ($git) = @_; - $git->cleanup(1) and - PublicInbox::DS::add_timer(3, \&git_tmp_cleanup, $git); -} - sub ibx_async_cat ($$$$) { my ($ibx, $oid, $cb, $arg) = @_; my $git = $ibx->{git} // $ibx->git; @@ -69,8 +63,6 @@ sub ibx_async_cat ($$$$) { $git->{async_cat} //= do { my $self = bless { git => $git }, __PACKAGE__; $git->{in}->blocking(0); - $git->{-tmp} and PublicInbox::DS::add_uniq_timer( - 3, \&git_tmp_cleanup, $git); $self->SUPER::new($git->{in}, EPOLLIN|EPOLLET); \undef; # this is a true ref() }; diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 915cf2c5..b0f58455 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -414,6 +414,7 @@ blob $oid $size bytes $raw_link EOM } @{$ctx->{-paths}} = ($path, $raw_link); + bless $ctx, 'PublicInbox::WwwStream'; # for DESTROY $ctx->{git} = $git; if ($ctx->{env}->{'pi-httpd.async'}) { ibx_async_cat($ctx, $oid, \&show_blob, $ctx); diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index 77b6f9c2..16442d51 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -220,4 +220,9 @@ sub html_init { print { $ctx->zfh } html_top($ctx); } +sub DESTROY { + my ($ctx) = @_; + $ctx->{git}->cleanup if $ctx->{git} && $ctx->{git}->{-tmp}; +} + 1;