From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 3/3] git-http-backend: fix aborts for generic PSGI clone
Date: Fri, 27 May 2016 06:17:38 +0000 [thread overview]
Message-ID: <20160527061738.21132-4-e@80x24.org> (raw)
In-Reply-To: <20160527061738.21132-1-e@80x24.org>
We need to avoid circular references in the generic PSGI layer,
do it by abusing DESTROY.
---
lib/PublicInbox/GetlineBody.pm | 31 +++++++++++++++++++++++++++++++
lib/PublicInbox/GitHTTPBackend.pm | 13 ++++---------
2 files changed, 35 insertions(+), 9 deletions(-)
create mode 100644 lib/PublicInbox/GetlineBody.pm
diff --git a/lib/PublicInbox/GetlineBody.pm b/lib/PublicInbox/GetlineBody.pm
new file mode 100644
index 0000000..4f8765b
--- /dev/null
+++ b/lib/PublicInbox/GetlineBody.pm
@@ -0,0 +1,31 @@
+# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Wrap a pipe or file for PSGI streaming response bodies and calls the
+# end callback when the object goes out-of-scope.
+# This depends on rpipe being _blocking_ on getline.
+package PublicInbox::GetlineBody;
+use strict;
+use warnings;
+
+sub new {
+ my ($class, $rpipe, $end, $buf) = @_;
+ bless { rpipe => $rpipe, end => $end, buf => $buf }, $class;
+}
+
+sub DESTROY { $_[0]->close }
+
+sub getline {
+ my ($self) = @_;
+ my $buf = delete $self->{buf};
+ defined $buf ? $buf : $self->{rpipe}->getline;
+}
+
+sub close {
+ my ($self) = @_;
+ delete $self->{rpipe};
+ my $end = delete $self->{end} or return;
+ $end->();
+}
+
+1;
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 9464cb4..fd7afbc 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -186,7 +186,7 @@ sub serve_smart {
my $x = PublicInbox::Qspawn->new([qw(git http-backend)], \%env, \%rdr);
my ($fh, $rpipe);
my $end = sub {
- $rpipe = undef;
+ close $rpipe if $rpipe && !$fh; # generic PSGI
if (my $err = $x->finish) {
err($env, "git http-backend ($git_dir): $err");
drop_client($env);
@@ -201,7 +201,7 @@ sub serve_smart {
my $r = sysread($rpipe, $buf, 1024, length($buf));
return if !defined($r) && ($!{EINTR} || $!{EAGAIN});
return r(500, 'http-backend error') unless $r;
- $r = parse_cgi_headers(\$buf) or return;
+ $r = parse_cgi_headers(\$buf) or return; # incomplete headers
$r->[0] == 403 ? serve_dumb($cgi, $git, $path) : $r;
};
my $res;
@@ -220,13 +220,8 @@ sub serve_smart {
}
# for synchronous PSGI servers
- $r->[2] = Plack::Util::inline_object(
- close => $end,
- getline => sub {
- my $ret = $buf;
- $buf = undef;
- defined $ret ? $ret : $rpipe->getline;
- });
+ require PublicInbox::GetlineBody;
+ $r->[2] = PublicInbox::GetlineBody->new($rpipe, $end, $buf);
$res->($r);
};
sub {
prev parent reply other threads:[~2016-05-27 6:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-27 6:17 [PATCH 0/3] http: another round EPIPE fixes Eric Wong
2016-05-27 6:17 ` [PATCH 1/3] httpd/async: prevent circular reference Eric Wong
2016-05-27 7:32 ` [PATCH 4/3] httpd/async: do not needlessly weaken Eric Wong
2016-05-27 6:17 ` [PATCH 2/3] http: avoid circular reference for getline responses Eric Wong
2016-05-27 6:17 ` Eric Wong [this message]
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=20160527061738.21132-4-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).