Socket closing #7

Closed
vovpov opened this Issue Apr 13, 2012 · 3 comments

Projects

None yet

2 participants

@vovpov
vovpov commented Apr 13, 2012

Hello.
There is a such kind of situation:
I have a (moose) class that encapsulates RedisDB object. Objects of this class frequently creating and destroying - but after destroying i see that running process accumulates open sockets. It seems that when main object destroed, attribute with RedisDB not cleared yet. First i try write in my class next code:
sub DEMOLISH
{
my $self = shift;
$self->redis(undef) if defined $self->redis;
}
But this is not help. Next i try to write DESTROY method in your class like:
sub DESTROY
{
my $self = shift;
$self->{_socket}->close() if defined $self->{_socket};
}
and in my class i write in destructor $self->redis->DESTROY;
After that problems disappear and sockets closed after object destroying.
So maybe you need to add explicit DESTROY method in your class? or maybe i do something wrong )

Owner

That's weird. Can you provide me with more information - OS, perl and Moose
version. A working script would be ideal. I will look on this problem
tomorrow. Thank you for reporting this.

Owner

Ok, I was able to reproduce it myself with the following code:

use 5.010;
use strict;
use warnings;

use RedisDB;

for (1..10) {
    my $redis = RedisDB->new;
    $redis->set('test', $_);
}

say "Check connections";
<>;

Indeed connections stay open

Owner

The problem was introduced by 1.03 when I extracted parser into a separate module. Parser keeps a reference to the parent RedisDB object, and so prevents it from destruction. I just uploaded RedisDB-1.06 with the fix. Thanks again for the report.

@trinitum trinitum added a commit that closed this issue Apr 13, 2012
@trinitum fix memory leak
There was circular references between RedisDB and parser object,
as result RedisDB object wasn't destroyed. Thanks to vovpov@github
for discovering and reporting this problem. fixes #7
f7b7664
@trinitum trinitum closed this in f7b7664 Apr 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment