Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Weakening the reference to $client->{timer} to prevent a circlular re…

…ference
  • Loading branch information...
commit 3f316487010a4ef5a832f998bdc11ca00e423698 1 parent 52bc020
@jshirley jshirley authored committed
Showing with 21 additions and 0 deletions.
  1. +2 −0  lib/Tatsumaki/MessageQueue.pm
  2. +19 −0 t/mq_leak.t
View
2  lib/Tatsumaki/MessageQueue.pm
@@ -72,6 +72,7 @@ sub flush_events {
undef $client;
delete $self->clients->{$client_id};
};
+ Scalar::Util::weaken $client->{timer};
}
} catch {
/Tatsumaki::Error::ClientDisconnect/ and do {
@@ -101,6 +102,7 @@ sub poll_once {
warn "Timing out $client_id long-poll" if DEBUG;
$self->flush_events($client_id);
};
+ Scalar::Util::weaken $client->{timer};
# flush backlog for a new client
if ($is_new) {
View
19 t/mq_leak.t
@@ -0,0 +1,19 @@
+use Test::More;
+
+use AE;
+use Test::Memory::Cycle;
+
+use Tatsumaki::MessageQueue;
+
+srand(time ** $$);
+
+my $channel = 'test1';
+
+my $client_id = rand(1);
+
+my $instance = Tatsumaki::MessageQueue->instance( $channel );
+$instance->poll_once($client_id, sub { });
+
+memory_cycle_ok( $instance );
+
+done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.