p5-RedisDB / RedisDB

Perl extension to access Redis
22 stars 11 forks source link

Socket closing #7

Closed vovpov closed 12 years ago

vovpov commented 12 years ago

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 )

trinitum commented 12 years ago

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.

trinitum commented 12 years ago

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

trinitum commented 12 years ago

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.