about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-03-12 01:18:30 +0000
committerEric Wong <e@80x24.org>2019-04-04 09:13:58 +0000
commit7661a5732ebf4470339c1293b2ea32082af887be (patch)
tree4bf344691bae2df70ad138f88c86f749b184b17a
parent89be7a1b89a60446fc0a385c5c1cfaeec2f92c88 (diff)
downloadpublic-inbox-7661a5732ebf4470339c1293b2ea32082af887be.tar.gz
I mainly need this to enforce RLIMIT_CPU (and RLIMIT_CORE)
when requests come which generate giant, unrealistic diffs.

Per-coderepo limiters may be added in the future.  But for now,
I need to prevent cgit from monopolizing resources on my dinky
server.
-rw-r--r--Documentation/public-inbox-config.pod4
-rw-r--r--lib/PublicInbox/Cgit.pm3
-rw-r--r--lib/PublicInbox/Config.pm2
3 files changed, 7 insertions, 2 deletions
diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod
index dae69987..d6ecd086 100644
--- a/Documentation/public-inbox-config.pod
+++ b/Documentation/public-inbox-config.pod
@@ -231,6 +231,10 @@ the default limiter.
 C<RLIMIT_*> keys may be set to enforce resource limits for
 a particular limiter.
 
+Default named-limiters are prefixed with "-".  Currently,
+the "-cgit" named limiter is reserved for instances spawning
+cgit via C<publicinbox.cgitrc>
+
 =over 8
 
 =item publicinboxlimiter.<name>.max
diff --git a/lib/PublicInbox/Cgit.pm b/lib/PublicInbox/Cgit.pm
index 3d1a0d54..9ba9e14d 100644
--- a/lib/PublicInbox/Cgit.pm
+++ b/lib/PublicInbox/Cgit.pm
@@ -77,7 +77,8 @@ sub call {
 
         my $rdr = input_prepare($env) or return r(500);
         my $qsp = PublicInbox::Qspawn->new($self->{cmd}, $cgi_env, $rdr);
-        $qsp->psgi_return($env, undef, sub {
+        my $limiter = $self->{pi_config}->limiter('-cgit');
+        $qsp->psgi_return($env, $limiter, sub {
                 my ($r, $bref) = @_;
                 my $res = parse_cgi_headers($r, $bref) or return; # incomplete
                 $res;
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 6f62712f..9c1c3e2c 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -132,7 +132,7 @@ sub limiter {
         my ($self, $name) = @_;
         $self->{-limiters}->{$name} ||= do {
                 require PublicInbox::Qspawn;
-                my $max = $self->{"publicinboxlimiter.$name.max"};
+                my $max = $self->{"publicinboxlimiter.$name.max"} || 1;
                 my $limiter = PublicInbox::Qspawn::Limiter->new($max);
                 $limiter->setup_rlimit($name, $self);
                 $limiter;