Subject: | lost connection handling broken due to wrong %sock_map indexing |
Cache::Memcached 1.21 doesn't ever attempt to re-connect, and keeps
trying to use stale sockets. This is an issue in long-lived processes,
because the package variables %sock_map and %cache_sock don't ever get
refreshed.
The use of %sock_map is broken due to the fact that $sock stringifies
differently than \$sock:
# Stringified sock $sock: GLOB(0x504290)
# Stringified ref to sock \$sock: REF(0x505030)
Since you store new sockets with $sock_map{$sock} = $host;, but retrieve
them with $sock_map{\$sock}, you never get back the correct $ipport
string. This prevents the _dead_sock() and _close_sock() routines from
functioning as intended.
Observed on Perl 5.8.8.
The patch below fixes this issue.
Rhesa
--- lib/Cache/Memcached_orig.pm 2007-05-17 20:48:32.578814506 +0200
+++ lib/Cache/Memcached.pm 2007-05-17 23:44:30.912864044 +0200
@@ -162,12 +162,12 @@ my %sock_map; # scalaraddr -> "$ip:$por
sub _dead_sock {
my ($sock, $ret, $dead_for) = @_;
- if (my $ipport = $sock_map{\$sock}) {
+ 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};
+ delete $sock_map{$sock};
}
@buck2sock = ();
return $ret; # 0 or undef, probably, depending on what caller wants
@@ -175,10 +175,10 @@ sub _dead_sock {
sub _close_sock {
my ($sock) = @_;
- if (my $ipport = $sock_map{\$sock}) {
+ if (my $ipport = $sock_map{$sock}) {
close $sock;
delete $cache_sock{$ipport};
- delete $sock_map{\$sock};
+ delete $sock_map{$sock};
}
@buck2sock = ();
}