From 56692b57c4e6a404fee0ec8eef857f35e09ce767 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 May 2016 04:39:57 +0000 Subject: http: yield body->getline running time We cannot let a client monopolize the single-threaded server even if it can drain the socket buffer faster than we can emit data. While we're at it, acknowledge the this behavior (which happens naturally) in httpd/async. The same idea is present in NNTP for the long_response code. This is the HTTP followup to: commit 0d0fde0bff97 ("nntp: introduce long response API for streaming") commit 79d8bfedcdd2 ("nntp: avoid signals for long responses") --- lib/PublicInbox/HTTP.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/HTTP.pm') diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index fcbd758a..6df1c3fc 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -265,10 +265,13 @@ sub getline_response { my $pull = $self->{pull} = sub { local $/ = \8192; my $forward = $self->{forward}; + # limit our own running time for fairness with other + # clients and to avoid buffering too much: + my $n = 100; while ($forward && defined(my $buf = $forward->getline)) { $write->($buf); last if $self->{closed}; - if ($self->{write_buf_size}) { + if ((--$n) <= 0 || $self->{write_buf_size}) { $self->write($self->{pull}); return; } -- cgit v1.2.3-24-ge0c7