diff options
author | Eric Wong <e@80x24.org> | 2016-05-27 05:59:14 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-27 06:01:52 +0000 |
commit | 395406118cb22b4cfa3a83c2b3a3a9aa2627b708 (patch) | |
tree | 3f03096aa963f355a6970d0aa62be7855a93a69e /lib/PublicInbox | |
parent | 23a4e44bedabe5b8b651346cabc2a870c5377a30 (diff) | |
download | public-inbox-395406118cb22b4cfa3a83c2b3a3a9aa2627b708.tar.gz |
We must avoid circular references which can cause leaks in long-running processes. This callback is dangerous since it may never be called to properly terminate everything.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/HTTPD/Async.pm | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/PublicInbox/HTTPD/Async.pm b/lib/PublicInbox/HTTPD/Async.pm index 47ba27d2..b00e6370 100644 --- a/lib/PublicInbox/HTTPD/Async.pm +++ b/lib/PublicInbox/HTTPD/Async.pm @@ -10,6 +10,7 @@ use strict; use warnings; use base qw(Danga::Socket); use fields qw(cb cleanup); +use Scalar::Util qw(weaken); require PublicInbox::EvCleanup; sub new { @@ -25,11 +26,12 @@ sub new { sub async_pass { my ($self, $io, $fh, $bref) = @_; - my $restart_read = sub { $self->watch_read(1) }; # In case the client HTTP connection ($io) dies, it # will automatically close this ($self) object. $io->{forward} = $self; $fh->write($$bref); + weaken($self); + my $restart_read = sub { $self->watch_read(1) }; $self->{cb} = sub { my $r = sysread($self->{sock}, $$bref, 8192); if ($r) { |