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")
-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;
sub ibx_async_cat ($$$$) {
my ($ibx, $oid, $cb, $arg) = @_;
my $git = $ibx->{git} // $ibx->git;
$git->{async_cat} //= do {
my $self = bless { git => $git }, __PACKAGE__;
$git->{in}->blocking(0);
$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()
};
$self->SUPER::new($git->{in}, EPOLLIN|EPOLLET);
\undef; # this is a true ref()
};
EOM
}
@{$ctx->{-paths}} = ($path, $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);
$ctx->{git} = $git;
if ($ctx->{env}->{'pi-httpd.async'}) {
ibx_async_cat($ctx, $oid, \&show_blob, $ctx);
print { $ctx->zfh } html_top($ctx);
}
print { $ctx->zfh } html_top($ctx);
}
+sub DESTROY {
+ my ($ctx) = @_;
+ $ctx->{git}->cleanup if $ctx->{git} && $ctx->{git}->{-tmp};
+}
+