From 2262411eb4396b2627e131ce4cd402a2deebdbea Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 31 Dec 2019 10:30:09 +0000 Subject: wwwstatic: getline: die on missing psgix.io "psgix." extensions aren't guaranteed, so make we should try and support some theoretical generic PSGI servers without "psgix.io" on errors by die-ing. While we're at it, make the error handling path more obvious by sharing more code between the EOF and errno ($!) cases. --- lib/PublicInbox/WwwStatic.pm | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/PublicInbox/WwwStatic.pm') diff --git a/lib/PublicInbox/WwwStatic.pm b/lib/PublicInbox/WwwStatic.pm index 76e50c78..58db58b4 100644 --- a/lib/PublicInbox/WwwStatic.pm +++ b/lib/PublicInbox/WwwStatic.pm @@ -77,25 +77,23 @@ sub response { # called by PSGI servers: sub getline { my ($self) = @_; - my $len = $self->{len}; - return if $len == 0; + my $len = $self->{len} or return; # undef, tells server we're done my $n = delete($self->{initial_rd}) // 8192; $n = $len if $len < $n; my $r = sysread($self->{in}, my $buf, $n); - if (!defined $r) { - $self->{env}->{'psgi.errors'}->print( - "$self->{path} read error: $!\n"); - } elsif ($r > 0) { # success! + if (defined $r && $r > 0) { # success! $self->{len} = $len - $r; return $buf; - } else { - $self->{env}->{'psgi.errors'}->print( - "$self->{path} EOF with $len bytes left\n"); } + my $m = defined $r ? "EOF with $len bytes left" : "read error: $!"; + my $env = $self->{env}; + $env->{'psgi.errors'}->print("$self->{path} $m\n"); # drop the client on error - if (my $io = $self->{env}->{'psgix.io'}) { - $io->close; # this is PublicInbox::DS::close + if (my $io = $env->{'psgix.io'}) { + $io->close; # this is likely PublicInbox::DS::close + } else { # for some PSGI servers w/o psgix.io + die "dropping client socket\n"; } undef; } -- cgit v1.2.3-24-ge0c7