Cache::Memcached issue

Jason Titus
Mon, 15 Mar 2004 18:00:26 -0800

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

We found an issue connecting to multiple caches on the same host.  The 
dead_hosts hash contains both the hostname:port AND just the hostname.  
This means that if one process goes down on a machine, all the 
connections to the other ports will fail (silently).

Here is a proposed patch that folks may or may not like.  I'm not sure 
what the logic was of including the hostname as well as the 
hostname:port combo.  Perhaps there is a benefit that I'm not thinking of.

Let me know what you think.  Without this, we have to manually call 
'Cache::Memcached::forget_dead_hosts()' between each call.

Also, is there any plan to add in some kind of connection check to 
Cache::Memcached?  It is kind of a bummer to only find out that a 
connection isn't working when you try and 'get' or 'set' something.  A 
failure on 'new' would make sense if there is no cache at a particular 


Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;

--- Cache-Memcached-1.0.11/	2003-10-26 01:04:36.000000000 -0800
+++ Cache-Memcached-1.0.11-dead-host-fix/	2004-03-15 17:51:12.000000000 -0800
@@ -95,7 +95,7 @@
         my $now = time();
         my ($ip, $port) = ($1, $2);
         my $host = "$ip:$port";
-        $host_dead{$host} = $host_dead{$ip} = $now + 30 + int(rand(10));
+        $host_dead{$host} = $now + 30 + int(rand(10));
         delete $cache_sock{$host};
     return $ret;  # 0 or undef, probably, depending on what caller wants
@@ -144,8 +144,7 @@
     my $now = time();
     my ($ip, $port) = $host =~ /(.*):(\d+)/;
     return undef if 
-         $host_dead{$host} && $host_dead{$host} > $now || 
-         $host_dead{$ip} && $host_dead{$ip} > $now;
+         $host_dead{$host} && $host_dead{$host} > $now; 
     my $sock = "Sock_$host";
     my $proto = $PROTO_TCP ||= getprotobyname('tcp');