X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FQspawn.pm;h=779b703a0f270cf81196279c7f616a6b7c7283ac;hb=a1ee3e0d84fedc4a2dd4e16e7054ee6fdfbe111a;hp=f8cbffcb359b74629a888119bcbba4237335d0ad;hpb=81a906c55b9510b38ea035dca13475fdd9d27083;p=public-inbox.git diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm index f8cbffcb..779b703a 100644 --- a/lib/PublicInbox/Qspawn.pm +++ b/lib/PublicInbox/Qspawn.pm @@ -25,10 +25,10 @@ # processes such as git-apply(1). package PublicInbox::Qspawn; -use strict; -use v5.10.1; +use v5.12; use PublicInbox::Spawn qw(popen_rd); use PublicInbox::GzipFilter; +use Scalar::Util qw(blessed); # n.b.: we get EAGAIN with public-inbox-httpd, and EINTR on other PSGI servers use Errno qw(EAGAIN EINTR); @@ -134,7 +134,7 @@ sub start ($$$) { } } -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); @@ -201,7 +201,7 @@ sub rd_hdr ($) { my $total_rd = 0; my $hdr_buf = $self->{hdr_buf}; my ($ph_cb, $ph_arg) = @{$self->{parse_hdr}}; - do { + until (defined($ret)) { my $r = sysread($self->{rpipe}, $$hdr_buf, 4096, length($$hdr_buf)); if (defined($r)) { @@ -210,6 +210,12 @@ sub rd_hdr ($) { if ($@) { warn "parse_hdr: $@"; $ret = [ 500, [], [ "Internal error\n" ] ]; + } elsif (!defined($ret) && !$r) { + my $cmd = $self->{cmd} // [ '(?)' ]; + warn <{psgi_env}->{REQUEST_URI}) +EOM + $ret = [ 500, [], [ "Internal error\n" ] ]; } } else { # caller should notify us when it's ready: @@ -218,18 +224,19 @@ sub rd_hdr ($) { warn "error reading header: $!"; $ret = [ 500, [], [ "Internal error\n" ] ]; } - } until (defined $ret); + } 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}; my $filter; - if (ref($r) eq 'ARRAY' && Scalar::Util::blessed($r->[2]) && - $r->[2]->can('attach')) { + + # this is for RepoAtom since that can fire after parse_cgi_headers + if (ref($r) eq 'ARRAY' && blessed($r->[2]) && $r->[2]->can('attach')) { $filter = pop @$r; } $filter //= delete($env->{'qspawn.filter'}) // (ref($r) eq 'ARRAY' ? @@ -325,8 +332,7 @@ sub psgi_return { } package PublicInbox::Qspawn::Limiter; -use strict; -use warnings; +use v5.12; sub new { my ($class, $max) = @_;