user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/4] httpd/async: retry reads properly when parsing headers
  2023-01-06 10:10  6% [PATCH 0/4] www_coderepo vs cgit fallback fixes Eric Wong
@ 2023-01-06 10:10  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2023-01-06 10:10 UTC (permalink / raw)
  To: meta

While git-http-backend sends headers with one write syscall,
upstream cgit still trickles them out line-by-line and we need to
account for that and retry Qspawn {parse_hdr} callbacks.
---
 lib/PublicInbox/HTTPD/Async.pm | 8 +++++---
 lib/PublicInbox/Qspawn.pm      | 4 ++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index e03daafa..7bbab1e1 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -14,7 +14,7 @@
 # arg: arg for {cb}
 # end_obj: CODE or object which responds to ->event_step when ->close is called
 package PublicInbox::HTTPD::Async;
-use strict;
+use v5.12;
 use parent qw(PublicInbox::DS);
 use Errno qw(EAGAIN);
 use PublicInbox::Syscall qw(EPOLLIN);
@@ -44,9 +44,9 @@ sub new {
 
 sub event_step {
 	my ($self) = @_;
-	if (my $cb = delete $self->{cb}) {
+	if (defined $self->{cb}) {
 		# this may call async_pass when headers are done
-		$cb->(my $refcnt_guard = delete $self->{arg});
+		$self->{cb}->($self->{arg});
 	} elsif (my $sock = $self->{sock}) {
 		# $http may be undef if discarding body output from cgit on 404
 		my $http = $self->{http} or return $self->close;
@@ -76,6 +76,7 @@ sub event_step {
 # may be PublicInbox::GzipFilter or $PublicInbox::Qspawn::qx_fh
 sub async_pass {
 	my ($self, $http, $ofh, $bref) = @_;
+	delete @$self{qw(cb arg)};
 	# In case the client HTTP connection ($http) dies, it
 	# will automatically close this ($self) object.
 	$http->{forward} = $self;
@@ -94,6 +95,7 @@ sub async_pass {
 sub close {
 	my $self = $_[0];
 	$self->SUPER::close; # DS::close
+	delete @$self{qw(cb arg)};
 
 	# we defer this to the next timer loop since close is deferred
 	if (my $end_obj = delete $self->{end_obj}) {
diff --git a/lib/PublicInbox/Qspawn.pm b/lib/PublicInbox/Qspawn.pm
index f8cbffcb..7984e35a 100644
--- a/lib/PublicInbox/Qspawn.pm
+++ b/lib/PublicInbox/Qspawn.pm
@@ -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);
@@ -223,7 +223,7 @@ sub rd_hdr ($) {
 	$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};

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/4] www_coderepo vs cgit fallback fixes
@ 2023-01-06 10:10  6% Eric Wong
  2023-01-06 10:10  7% ` [PATCH 2/4] httpd/async: retry reads properly when parsing headers Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2023-01-06 10:10 UTC (permalink / raw)
  To: meta

2/4 is critical in that it fixes occasional 500 errors noticed
in my cgit -> www_coderepo migration.  There's a few other
problems noticed an fixed along the way as well; having to
contort our code to PSGI expectations leads to some awkwardness,
unfortunately :<

Eric Wong (4):
  qspawn: use fallback response code from CGI program
  httpd/async: retry reads properly when parsing headers
  qspawn: consistently return 500 on premature EOF
  qspawn: fix EINTR with generic PSGI servers

 lib/PublicInbox/GitHTTPBackend.pm |  1 +
 lib/PublicInbox/HTTPD/Async.pm    |  8 +++++---
 lib/PublicInbox/Qspawn.pm         | 18 +++++++++++++-----
 3 files changed, 19 insertions(+), 8 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-01-06 10:10  6% [PATCH 0/4] www_coderepo vs cgit fallback fixes Eric Wong
2023-01-06 10:10  7% ` [PATCH 2/4] httpd/async: retry reads properly when parsing headers Eric Wong

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).