lib/PublicInbox/HTTPD/Async.pm | 8 +++++--- lib/PublicInbox/Qspawn.pm | 4 ++-- diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index e03daafac8d1a7994042fa52e94e4eac60f7ac4c..7bbab1e1cd65c22d2a895f5a99b5924fa172afd5 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -14,7 +14,7 @@ # cb: initial read callback # arg: arg for {cb} # end_obj: CODE or object which responds to ->event_step when ->close is called package PublicInbox::HTTPD::Async; -use strict; +use v5.12; use parent qw(PublicInbox::DS); use Errno qw(EAGAIN); use PublicInbox::Syscall qw(EPOLLIN); @@ -44,9 +44,9 @@ } sub event_step { my ($self) = @_; - if (my $cb = delete $self->{cb}) { + if (defined $self->{cb}) { # this may call async_pass when headers are done - $cb->(my $refcnt_guard = delete $self->{arg}); + $self->{cb}->($self->{arg}); } elsif (my $sock = $self->{sock}) { # $http may be undef if discarding body output from cgit on 404 my $http = $self->{http} or return $self->close; @@ -76,6 +76,7 @@ # $ofh is typically PublicInbox::HTTP::{Chunked,Identity}, but # may be PublicInbox::GzipFilter or $PublicInbox::Qspawn::qx_fh sub async_pass { my ($self, $http, $ofh, $bref) = @_; + delete @$self{qw(cb arg)}; # In case the client HTTP connection ($http) dies, it # will automatically close this ($self) object. $http->{forward} = $self; @@ -94,6 +95,7 @@ # may be called as $forward->close in PublicInbox::HTTP or EOF (event_step) sub close { my $self = $_[0]; $self->SUPER::close; # DS::close + delete @$self{qw(cb arg)}; # we defer this to the next timer loop since close is deferred if (my $end_obj = delete $self->{end_obj}) { diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index f8cbffcb359b74629a888119bcbba4237335d0ad..7984e35a80510ffdf09cbb7f5e325ecd9eb764a0 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -134,7 +134,7 @@ push @{$limiter->{run_queue}}, [ $self, $start_cb ]; } } -sub psgi_qx_init_cb { +sub psgi_qx_init_cb { # this may be PublicInbox::HTTPD::Async {cb} my ($self) = @_; my $async = delete $self->{async}; # PublicInbox::HTTPD::Async my ($r, $buf); @@ -223,7 +223,7 @@ delete $self->{parse_hdr}; # done parsing headers $ret; } -sub psgi_return_init_cb { +sub psgi_return_init_cb { # this may be PublicInbox::HTTPD::Async {cb} my ($self) = @_; my $r = rd_hdr($self) or return; my $env = $self->{psgi_env};