]> Sergey Matveev's repositories - public-inbox.git/commitdiff
http: eliminate short-lived cyclic ref for psgix.io
authorEric Wong <e@yhbt.net>
Fri, 24 Jan 2020 09:43:49 +0000 (09:43 +0000)
committerEric Wong <e@yhbt.net>
Sat, 25 Jan 2020 19:20:37 +0000 (19:20 +0000)
While there is no known actual leak due to reference cycles,
here, eliminating a potential source of leaks is helpful.

lib/PublicInbox/HTTP.pm

index 325371535995ce0a343277bd6fcc603f2cc9493b..b19a15d643c23f3c9d19df6df69892d725fa322c 100644 (file)
@@ -80,7 +80,7 @@ sub event_step { # called by PublicInbox::DS
        # only read more requests if we've drained the write buffer,
        # otherwise we can be buffering infinitely w/o backpressure
 
-       return read_input($self) if defined $self->{env};
+       return read_input($self) if ref($self->{env});
        my $rbuf = $self->{rbuf} // (\(my $x = ''));
        $self->do_read($rbuf, 8192, bytes::length($$rbuf)) or return;
        rbuf_process($self, $rbuf);
@@ -124,7 +124,6 @@ sub read_input ($;$) {
        my ($self, $rbuf) = @_;
        $rbuf //= $self->{rbuf} // (\(my $x = ''));
        my $env = $self->{env};
-       return if $env->{REMOTE_ADDR}; # in app dispatch
        return read_input_chunked($self, $rbuf) if env_chunked($env);
 
        # env->{CONTENT_LENGTH} (identity)
@@ -153,6 +152,7 @@ sub app_dispatch {
        my ($self, $input, $rbuf) = @_;
        $self->rbuf_idle($rbuf);
        my $env = $self->{env};
+       $self->{env} = undef; # for exists() check in ->busy
        $env->{REMOTE_ADDR} = $self->{remote_addr};
        $env->{REMOTE_PORT} = $self->{remote_port};
        if (defined(my $host = $env->{HTTP_HOST})) {
@@ -455,7 +455,6 @@ sub quit {
 
 sub close {
        my $self = $_[0];
-       delete $self->{env}; # prevent circular references
        if (my $forward = delete $self->{forward}) {
                eval { $forward->close };
                err($self, "forward ->close error: $@") if $@;
@@ -466,7 +465,7 @@ sub close {
 # for graceful shutdown in PublicInbox::Daemon:
 sub busy () {
        my ($self) = @_;
-       ($self->{rbuf} || $self->{env} || $self->{wbuf});
+       ($self->{rbuf} || exists($self->{env}) || $self->{wbuf});
 }
 
 # Chunked and Identity packages are used for writing responses.