Skip to content

Commit

Permalink
Weakening the reference to $client->{timer} to prevent a circlular re…
Browse files Browse the repository at this point in the history
…ference
  • Loading branch information
jshirley authored and miyagawa committed Dec 8, 2009
1 parent 52bc020 commit 3f31648
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Tatsumaki/MessageQueue.pm
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions 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;

0 comments on commit 3f31648

Please sign in to comment.