From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CB4F21F724 for ; Wed, 13 Dec 2023 00:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1702428621; bh=wXxR8WzV7jJ52QEh1GumyTDO2z7RzvRzLVoFDIZpLpA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hrnTpZqi4ydO+nETz9s1fJUHa6Y0nyDpSgfx4FbmQivSn+ALFjY7ytrzy0QAjB6vg k54ME/XTX1xe2o2zbB1B4gSaD+F4HnmvpgbzzCH4+0oymI9w0DDrA+j0fenSWhE43z iza/HbyDrlFelrcTo8ozC8ovBvW1jF3fWzjCKdMo= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/14] www_coderepo: fix read buffering Date: Wed, 13 Dec 2023 00:50:17 +0000 Message-ID: <20231213005019.26912-13-e@80x24.org> In-Reply-To: <20231213005019.26912-1-e@80x24.org> References: <20231213005019.26912-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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('') } # 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">
 	}
 	$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('
', $_[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');