From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/5] wwwstatic: getline: die on missing psgix.io
Date: Tue, 31 Dec 2019 10:30:09 +0000 [thread overview]
Message-ID: <20191231103013.9133-2-e@80x24.org> (raw)
In-Reply-To: <20191231103013.9133-1-e@80x24.org>
"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(-)
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;
}
next prev parent reply other threads:[~2019-12-31 10:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-31 10:30 [PATCH 0/5] some minor cleanups and doc updates Eric Wong
2019-12-31 10:30 ` Eric Wong [this message]
2019-12-31 10:30 ` [PATCH 2/5] http: update comment about psgix.io usage Eric Wong
2019-12-31 10:30 ` [PATCH 3/5] githttpbackend: remove ancient compatibility check Eric Wong
2019-12-31 10:30 ` [PATCH 4/5] filter/base: export REJECT as a constant Eric Wong
2019-12-31 10:30 ` [PATCH 5/5] cgit: type declaration for PublicInbox::Git Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191231103013.9133-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).