]> Sergey Matveev's repositories - public-inbox.git/commitdiff
httpd/async: stop running command if client disconnects
authorEric Wong <e@80x24.org>
Fri, 13 Jan 2017 23:10:25 +0000 (23:10 +0000)
committerEric Wong <e@80x24.org>
Tue, 22 Jan 2019 03:40:18 +0000 (03:40 +0000)
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.

lib/PublicInbox/HTTPD/Async.pm

index a9a9573b28cf4609f1880ece72034cb3e6e7aa3c..a1f7551819700e1a48d91f7aa36818a4e5a3ee80 100644 (file)
@@ -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};
                }