unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/3] minor httpd related tweaks
@ 2016-03-01  8:31 Eric Wong
  2016-03-01  8:31 ` [PATCH 1/3] httpd: document pi-httpd.async as totally unstable Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2016-03-01  8:31 UTC (permalink / raw)
  To: meta

Fun times ahead :>

Eric Wong (3):
      httpd: document pi-httpd.async as totally unstable
      httpd: remove unneeded err and out fields from class
      http: better error handling for EMFILE/ENFILE

 lib/PublicInbox/GitHTTPBackend.pm |  2 +-
 lib/PublicInbox/HTTP.pm           | 16 +++++++++++++---
 script/public-inbox-httpd         |  6 ++++--
 3 files changed, 18 insertions(+), 6 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] httpd: document pi-httpd.async as totally unstable
  2016-03-01  8:31 [PATCH 0/3] minor httpd related tweaks Eric Wong
@ 2016-03-01  8:31 ` Eric Wong
  2016-03-01  8:31 ` [PATCH 2/3] httpd: remove unneeded err and out fields from class Eric Wong
  2016-03-01  8:31 ` [PATCH 3/3] http: better error handling for EMFILE/ENFILE Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-03-01  8:31 UTC (permalink / raw)
  To: meta

We'll have to use it some more before deciding it is a public
interface.  I do hope for it to be a usable public interface
one day for other users.
---
 lib/PublicInbox/GitHTTPBackend.pm | 2 +-
 script/public-inbox-httpd         | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 56bf24f..c84eefc 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -224,7 +224,7 @@ sub serve_smart {
 	if (my $async = $env->{'pi-httpd.async'}) {
 		$rpipe = $async->($rpipe, $cb);
 		sub { ($res) = @_ } # let Danga::Socket handle the rest.
-	} else { # synchronous loop
+	} else { # synchronous loop for other PSGI servers
 		$vin = '';
 		vec($vin, fileno($rpipe), 1) = 1;
 		sub {
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index f1a5d79..d407059 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -59,6 +59,10 @@ daemon_run('0.0.0.0:8080', $refresh,
 
 1;
 
+# XXX This is a totally unstable API for public-inbox internal use only
+# This is exposed via the 'pi-httpd.async' key in the PSGI env hash.
+# The name of this key is not even stable!
+# Currently is is intended for use with read-only pipes.
 package PublicInbox::HTTPD::Async;
 use strict;
 use warnings;
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] httpd: remove unneeded err and out fields from class
  2016-03-01  8:31 [PATCH 0/3] minor httpd related tweaks Eric Wong
  2016-03-01  8:31 ` [PATCH 1/3] httpd: document pi-httpd.async as totally unstable Eric Wong
@ 2016-03-01  8:31 ` Eric Wong
  2016-03-01  8:31 ` [PATCH 3/3] http: better error handling for EMFILE/ENFILE Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-03-01  8:31 UTC (permalink / raw)
  To: meta

Vestigial pieces from the nntpd code which aren't needed because
the psgi env already has the "psgi.errors" key.
---
 script/public-inbox-httpd | 2 --
 1 file changed, 2 deletions(-)

diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index d407059..2157962 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -129,8 +129,6 @@ sub new {
 		},
 	);
 	bless {
-		err => \*STDERR,
-		out => \*STDOUT,
 		app => $app,
 		env => \%env,
 	}, $class;
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] http: better error handling for EMFILE/ENFILE
  2016-03-01  8:31 [PATCH 0/3] minor httpd related tweaks Eric Wong
  2016-03-01  8:31 ` [PATCH 1/3] httpd: document pi-httpd.async as totally unstable Eric Wong
  2016-03-01  8:31 ` [PATCH 2/3] httpd: remove unneeded err and out fields from class Eric Wong
@ 2016-03-01  8:31 ` Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-03-01  8:31 UTC (permalink / raw)
  To: meta

Better to throw the error back to the client ASAP if we're
out-of-descriptors.  We will need to implement idle client
expiration for long-lived HTTP connections.
---
 lib/PublicInbox/HTTP.pm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index aaae7ab..17e7447 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -71,7 +71,10 @@ sub rbuf_process {
 	return quit($self, 400) if $r == -1 || $env{HTTP_TRAILER};
 	return $self->watch_read(1) if $r < 0; # incomplete
 	$self->{rbuf} = substr($self->{rbuf}, $r);
+
 	my $len = input_prepare($self, \%env);
+	defined $len or return write_err($self); # EMFILE/ENFILE
+
 	$len ? event_read_input($self) : app_dispatch($self);
 }
 
@@ -116,7 +119,10 @@ sub app_dispatch ($) {
 		$host =~ s/:(\d+)\z// and $env->{SERVER_PORT} = $1;
 		$env->{SERVER_NAME} = $host;
 	}
-	sysseek($env->{'psgi.input'}, 0, SEEK_SET) or die "input seek failed: $!";
+
+	sysseek($env->{'psgi.input'}, 0, SEEK_SET) or
+			die "BUG: psgi.input seek failed: $!";
+
 	my $res = Plack::Util::run_app($self->{httpd}->{app}, $env);
 	eval {
 		if (ref($res) eq 'CODE') {
@@ -222,13 +228,17 @@ sub input_prepare {
 	if ($len) {
 		$input = IO::File->new_tmpfile;
 	} elsif (env_chunked($env)) {
-		$input = IO::File->new_tmpfile;
 		$len = CHUNK_START;
+		$input = IO::File->new_tmpfile;
 	}
+
+	# TODO: expire idle clients on ENFILE / EMFILE
+	return unless $input;
+
 	binmode $input;
 	$env->{'psgi.input'} = $input;
 	$self->{env} = $env;
-	$self->{input_left} = $len;
+	$self->{input_left} = $len || 0;
 }
 
 sub env_chunked { ($_[0]->{HTTP_TRANSFER_ENCODING} || '') =~ /\bchunked\b/i }
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-03-01  8:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01  8:31 [PATCH 0/3] minor httpd related tweaks Eric Wong
2016-03-01  8:31 ` [PATCH 1/3] httpd: document pi-httpd.async as totally unstable Eric Wong
2016-03-01  8:31 ` [PATCH 2/3] httpd: remove unneeded err and out fields from class Eric Wong
2016-03-01  8:31 ` [PATCH 3/3] http: better error handling for EMFILE/ENFILE Eric Wong

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