diff options
-rw-r--r-- | lib/PublicInbox/HTTP.pm | 14 | ||||
-rw-r--r-- | lib/PublicInbox/WWW.pm | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index bbcb0898..1ef3fb31 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -24,6 +24,15 @@ use constant { CHUNK_MAX_HDR => 256, }; +# FIXME: duplicated code with NNTP.pm +my $WEAKEN = {}; # string(inbox) -> inbox +my $WEAKTIMER; +sub weaken_task () { + $WEAKTIMER = undef; + $_->weaken_all for values %$WEAKEN; + $WEAKEN = {}; +} + # Use the same configuration parameter as git since this is primarily # a slow-client sponge for git-http-backend # TODO: support per-respository http.maxRequestBuffer somehow... @@ -198,6 +207,11 @@ sub response_write { } else { $self->write(sub { $self->close }); } + if (my $obj = $env->{'pi-httpd.inbox'}) { + # grace period for reaping resources + $WEAKEN->{"$obj"} = $obj; + $WEAKTIMER ||= Danga::Socket->AddTimer(60, *weaken_task); + } $self->{env} = undef; }; diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm index 95288a7b..465dcb26 100644 --- a/lib/PublicInbox/WWW.pm +++ b/lib/PublicInbox/WWW.pm @@ -129,6 +129,8 @@ sub invalid_inbox { if (defined $obj) { $ctx->{git_dir} = $obj->{mainrepo}; $ctx->{git} = $obj->git; + # for PublicInbox::HTTP::weaken_task: + $ctx->{cgi}->{env}->{'pi-httpd.inbox'} = $obj; $ctx->{-inbox} = $obj; $ctx->{inbox} = $inbox; return; |