Some issues with how last Cache::Memcached version (1.21) handle closing sockets/disconnets

Brad Fitzpatrick brad at danga.com
Mon Jun 18 23:50:22 UTC 2007


This is now fixed in 1.22, tagged and uploaded to CPAN.

- Brad

On Mon, 4 Jun 2007, Boguk Maxim wrote:

> After update Perl memcached API to latest version i got some troubles
> with handle disconnect with memcached server:
>
> If perl code loose connection to memcached server he become spam next
> text:
>
> Use of uninitialized value in vec at
> /usr/local/lib/perl5/site_perl/5.8.8/Cache/Memcached.pm line 360.
> Use of uninitialized value in vec at
> /usr/local/lib/perl5/site_perl/5.8.8/Cache/Memcached.pm line 367.
> send() on closed socket $sock at
> /usr/local/lib/perl5/site_perl/5.8.8/Cache/Memcached.pm line 368.
> Use of uninitialized value in numeric gt (>) at
> /usr/local/lib/perl5/site_perl/5.8.8/Cache/Memcached.pm line 371.
> Use of uninitialized value in string eq at
> /usr/local/lib/perl5/site_perl/5.8.8/Cache/Memcached.pm line 492.
>
> And never attempt reconnect to memcached even if memcached full
> available...
>
>
> I looked into code and found some issues with how to %sock_map work:
>
> First inside function sock_to_host element of %sock_map hash initialize
> via:
> $sock_map{$sock} = $host;
>
> >From other hand we have 2 possible cleanup functions:
>
> sub _dead_sock {
>     my ($sock, $ret, $dead_for) = @_;
>     if (my $ipport = $sock_map{\$sock}) {
>         my $now = time();
>         $host_dead{$ipport} = $now + $dead_for
>             if $dead_for;
>         delete $cache_sock{$ipport};
>         delete $sock_map{\$sock};
>     }
>     @buck2sock = ();
>     return $ret;  # 0 or undef, probably, depending on what caller wants
> }
>
> sub _close_sock {
>     my ($sock) = @_;
>     if (my $ipport = $sock_map{\$sock}) {
>         close $sock;
>         delete $cache_sock{$ipport};
>         delete $sock_map{\$sock};
>     }
>     @buck2sock = ();
> }
>
> Both of these function trying clean $sock_map{\$sock} !
>
> So... Connect code set $sock_map{$sock} and cleanup code trying clean
> $sock_map{\$sock}   !?
>
> And of course dead sock never cleaning at all and API try use dead sock
> again and again.... (because bad socket permanently cached in %sock_map)
>
> This is really painful issue leading instability of projects.
>
>
> PS: Cache::Memcached installed from fresh FreeBSD ports (and i compared
> with fresh cpan version... They are same)
>
> PPS: I really sorry for bad English.
>
> ====================================================================
> SY Maxim Boguk
>
> astar at rambler-co.ru   ICQ: 99-312-438
> (910) 405-47-18
>
>
>


More information about the memcached mailing list