Bug in latest Perl Cache::Memcached module (1.21)

Boguk Maxim astar at rambler-co.ru
Wed Jun 6 09:46:24 UTC 2007

Somehow first mail didnt get to maillist. So second attempt:

After update Perl memcached API to latest version i got some troubles
with disconnects to memcached server:

If perl code loose connection to memcached server i get spam warnings:

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

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
$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