diff options
author | Eric Wong <e@80x24.org> | 2017-01-13 23:10:25 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-01-13 23:11:57 +0000 |
commit | 104021d888ef31b41bd6fdb41c272b3d14105935 (patch) | |
tree | b9a7c56fc587a020847132488c111651482c241d | |
parent | b3623ed3c06aa4ac2e47378d3c948c35a6809efa (diff) | |
download | public-inbox-104021d888ef31b41bd6fdb41c272b3d14105935.tar.gz |
If an HTTP client disconnects while we're piping the output of a process to them, break the pipe of the process to reclaim resources as soon as possible.
-rw-r--r-- | lib/PublicInbox/HTTPD/Async.pm | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index d3de4429..71175692 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -36,14 +36,16 @@ sub main_cb ($$$) { my $r = sysread($self->{sock}, $$bref, 8192); if ($r) { $fh->write($$bref); - return if $http->{closed}; - if ($http->{write_buf_size}) { - $self->watch_read(0); - $http->write(restart_read_cb($self)); + unless ($http->{closed}) { # Danga::Socket sets this + if ($http->{write_buf_size}) { + $self->watch_read(0); + $http->write(restart_read_cb($self)); + } + # stay in watch_read, but let other clients + # get some work done, too. + return; } - # stay in watch_read, but let other clients - # get some work done, too. - return; + # fall through to close below... } elsif (!defined $r) { return if $!{EAGAIN} || $!{EINTR}; } |