]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/HTTP.pm
http: release resources when idle
[public-inbox.git] / lib / PublicInbox / HTTP.pm
index bbcb0898612c905f4df1094ce8057c4b4547b832..1ef3fb31d8d6f8a61a1482860e33ddf5becc2b65 100644 (file)
@@ -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;
        };