about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTPD
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-05-27 07:23:18 +0000
committerEric Wong <e@80x24.org>2016-05-27 07:27:43 +0000
commitaa4e04c633ee857cb372d7e55c545d7a7b29d2eb (patch)
tree74aff8f2c45fcc29b31a50471590732998c5ed37 /lib/PublicInbox/HTTPD
parent79e11eea11dd561301a05c42ba824a7d352bd398 (diff)
downloadpublic-inbox-aa4e04c633ee857cb372d7e55c545d7a7b29d2eb.tar.gz
The restart_read callback has no chance of circular reference,
and weakening $self before we create it can cause $self to
be undefined inside the callback (seen during stress testing).

Fixes: 395406118cb2 ("httpd/async: prevent circular reference")
Diffstat (limited to 'lib/PublicInbox/HTTPD')
-rw-r--r--lib/PublicInbox/HTTPD/Async.pm7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm
index b00e6370..add07ce4 100644
--- a/lib/PublicInbox/HTTPD/Async.pm
+++ b/lib/PublicInbox/HTTPD/Async.pm
@@ -24,14 +24,19 @@ sub new {
         $self;
 }
 
+sub restart_read_cb ($) {
+        my ($self) = @_;
+        sub { $self->watch_read(1) }
+}
+
 sub async_pass {
         my ($self, $io, $fh, $bref) = @_;
         # In case the client HTTP connection ($io) dies, it
         # will automatically close this ($self) object.
         $io->{forward} = $self;
         $fh->write($$bref);
+        my $restart_read = restart_read_cb($self);
         weaken($self);
-        my $restart_read = sub { $self->watch_read(1) };
         $self->{cb} = sub {
                 my $r = sysread($self->{sock}, $$bref, 8192);
                 if ($r) {