unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 12/14] www_coderepo: fix read buffering
Date: Wed, 13 Dec 2023 00:50:17 +0000	[thread overview]
Message-ID: <20231213005019.26912-13-e@80x24.org> (raw)
In-Reply-To: <20231213005019.26912-1-e@80x24.org>

Our read buffering only worked well with the stdout buffering on
glibc and *BSD libc, but not musl.  When reading the stdout of
git(1), we are likely to get smaller buffers and require more
reads on musl-based systems (tested Alpine Linux 3.19.0).

Thus we must prevent ->translate from being called with an empty
argument list (denoting EOF).  We'll also avoid some local
variable assignments while at it and favor the non-OO ->zflush
dispatch inside RepoAtom and WwwCoderepo subclasses.
---
 lib/PublicInbox/RepoAtom.pm    | 4 ++--
 lib/PublicInbox/WwwCoderepo.pm | 6 +++---
 t/solver_git.t                 | 8 +++++---
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/RepoAtom.pm b/lib/PublicInbox/RepoAtom.pm
index c1649d0a..ab0f2fcc 100644
--- a/lib/PublicInbox/RepoAtom.pm
+++ b/lib/PublicInbox/RepoAtom.pm
@@ -43,7 +43,7 @@ sub zflush { $_[0]->SUPER::zflush('</feed>') }
 # called by GzipFilter->write or GetlineResponse->getline
 sub translate {
 	my $self = shift;
-	my $rec = $_[0] // return $self->zflush; # getline
+	$_[0] // return zflush($self); # getline caller
 	my @out;
 	my $lbuf = delete($self->{lbuf}) // shift;
 	$lbuf .= shift while @_;
@@ -87,7 +87,7 @@ xmlns="http://www.w3.org/1999/xhtml"><pre style="white-space:pre-wrap">
 	}
 	$self->{lbuf} = $lbuf;
 	chomp @out;
-	$self->SUPER::translate(@out);
+	@out ? $self->SUPER::translate(@out) : ''; # not EOF, yet
 }
 
 # $REPO/tags.atom endpoint
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index d1354af5..3814f719 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -273,7 +273,7 @@ sub zflush { $_[0]->SUPER::zflush('</pre>', $_[0]->_html_end) }
 # called by GzipFilter->write or GetlineResponse->getline
 sub translate {
 	my $ctx = shift;
-	my $rec = $_[0] // return zflush($ctx); # getline
+	$_[0] // return zflush($ctx); # getline caller
 	my @out;
 	my $fbuf = delete($ctx->{fbuf}) // shift;
 	$fbuf .= shift while @_;
@@ -290,8 +290,8 @@ sub translate {
 						$snap_pfx, @snap_fmt);
 		}
 	}
-	$ctx->{fbuf} = $fbuf;
-	$ctx->SUPER::translate(@out);
+	$ctx->{fbuf} = $fbuf; # may be incomplete
+	@out ? $ctx->SUPER::translate(@out) : ''; # not EOF, yet
 }
 
 sub _refs_parse_hdr { # {parse_hdr} for Qspawn
diff --git a/t/solver_git.t b/t/solver_git.t
index ab8aba15..db672904 100644
--- a/t/solver_git.t
+++ b/t/solver_git.t
@@ -405,14 +405,16 @@ EOF
 		is($res->code, 200, 'Atom feed');
 		SKIP: {
 			require_mods('XML::TreePP', 1);
-			my $t = XML::TreePP->new->parse($res->content);
+			my $t = eval { XML::TreePP->new->parse($res->content) }
+				or diag explain($res);
 			is(scalar @{$t->{feed}->{entry}}, 50,
-				'got 50 entries');
+				'got 50 entries') or diag explain([$t, $res]);
 
 			$res = $cb->(GET('/public-inbox/atom/COPYING'));
 			is($res->code, 200, 'file Atom feed');
 			$t = XML::TreePP->new->parse($res->content);
-			ok($t->{feed}->{entry}, 'got entry');
+			ok($t->{feed}->{entry}, 'got entry') or
+				diag explain([ $t, $res ]);
 
 			$res = $cb->(GET('/public-inbox/atom/README.md'));
 			is($res->code, 404, '404 on missing file Atom feed');

  parent reply	other threads:[~2023-12-13  0:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13  0:50 [PATCH 00/14] Alpine Linux support Eric Wong
2023-12-13  0:50 ` [PATCH 01/14] t/io: strace is optional on Linux Eric Wong
2023-12-13  0:50 ` [PATCH 02/14] tests: account for missing git-http-backend Eric Wong
2023-12-13  0:50 ` [PATCH 03/14] t/cindex*: skip --join when join(1) is missing Eric Wong
2023-12-13  0:50 ` [PATCH 04/14] tests: attempt compatibility w/ busybox lsof Eric Wong
2023-12-13  0:50 ` [PATCH 05/14] lei inspect: drop unneeded strftime import Eric Wong
2023-12-13  0:50 ` [PATCH 06/14] treewide: avoid strftime %k for portability Eric Wong
2023-12-13  0:50 ` [PATCH 07/14] xap_helper_cxx: decouple from Inline::C Eric Wong
2023-12-13  0:50 ` [PATCH 08/14] xap_helper_cxx: support clang w/o `c++' executable Eric Wong
2023-12-13  0:50 ` [PATCH 09/14] install: updates for Alpine Linux and apk Eric Wong
2023-12-13  0:50 ` [PATCH 10/14] test_common: extract oct_is from search.t Eric Wong
2023-12-13  0:50 ` [PATCH 11/14] t/convert-compact: allow S_ISGID bit Eric Wong
2023-12-13  0:50 ` Eric Wong [this message]
2023-12-13  0:50 ` [PATCH 13/14] gzip_filter: use OO ->zflush dispatch Eric Wong
2023-12-13  0:50 ` [PATCH 14/14] t/lei-import: relax EIO regexp 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: https://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=20231213005019.26912-13-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.
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).