]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
http: don't requeue if using write buffer
authorEric Wong <e@80x24.org>
Thu, 4 Jul 2024 02:20:55 +0000 (02:20 +0000)
committerEric Wong <e@80x24.org>
Thu, 4 Jul 2024 06:52:08 +0000 (06:52 +0000)
The write buffering will already be processed inside
->event_step, so requeue will cause a needless read(2) outside
of epoll_wait/kevent(2) readiness notifications.

This ought to avoid problems in case of pipelined connections,
but those aren't possible behind a reverse proxy and AFAIK most
HTTP clients don't do pipelining.  This bug was only noticed via
strace while searching for extra syscalls, and not from
real-world use.

lib/PublicInbox/HTTP.pm

index 4ccb1b817c30d69ad8ce683935362a34ba831037..88cab544739cb6d4643a701389b5542753281602 100644 (file)
@@ -247,7 +247,8 @@ sub response_done {
        delete $self->{env}; # we're no longer busy
        # HEAD requests set $alive = 3 so we don't send "0\r\n\r\n";
        $self->write(\"0\r\n\r\n") if $alive == 2;
-       $self->write($alive ? $self->can('requeue') : \&close);
+       $self->write(\&close) if !$alive;
+       $self->requeue if $alive && !$self->{wbuf};
 }
 
 sub getline_pull {
@@ -280,7 +281,7 @@ sub getline_pull {
                }
        } elsif ($@) {
                warn "response ->getline error: $@";
-               $self->close;
+               return $self->close;
        }
        response_done($self, delete $self->{alive});
 }