Index: /trunk/api/perl/t/05_reconnect_timeout.t
===================================================================
--- /trunk/api/perl/t/05_reconnect_timeout.t (revision 805)
+++ /trunk/api/perl/t/05_reconnect_timeout.t (revision 805)
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl -w
+
+use strict;
+use Test::More;
+use Cache::Memcached;
+use IO::Socket::INET;
+use Time::HiRes;
+
+my $testaddr = "192.0.2.1:11211";
+
+plan tests => 2;
+
+my $memd = Cache::Memcached->new({
+    servers   => [ $testaddr ],
+    namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/",
+});
+
+
+my $time1 = Time::HiRes::time();
+$memd->set("key", "bar");
+my $time2 = Time::HiRes::time();
+# 100ms is faster than the default connect timeout.
+ok($time2 - $time1 > .1, "Expected pause while connecting");
+
+# 100ms should be slow enough that dead socket reconnects happen faster than it.
+$memd->set("key", "foo");
+my $time3 = Time::HiRes::time();
+ok($time3 - $time2 < .1, "Should return fast on retry");
Index: /trunk/api/perl/lib/Cache/Memcached.pm
===================================================================
--- /trunk/api/perl/lib/Cache/Memcached.pm (revision 797)
+++ /trunk/api/perl/lib/Cache/Memcached.pm (revision 805)
@@ -245,4 +245,5 @@
         if ($self && $self->{pref_ip}{$ip}) {
             socket($sock, PF_INET, SOCK_STREAM, $proto);
+            $sock_map{$sock} = $host;
             my $prefip = $self->{pref_ip}{$ip};
             $sin = Socket::sockaddr_in($port,Socket::inet_aton($prefip));
@@ -260,4 +261,5 @@
         unless ($connected) {
             socket($sock, PF_INET, SOCK_STREAM, $proto);
+            $sock_map{$sock} = $host;
             $sin = Socket::sockaddr_in($port,Socket::inet_aton($ip));
             my $timeout = $self ? $self->{connect_timeout} : 0.25;
@@ -270,4 +272,5 @@
     } else { # it's a unix domain/local socket
         socket($sock, PF_UNIX, SOCK_STREAM, 0);
+        $sock_map{$sock} = $host;
         $sin = Socket::sockaddr_un($host);
         my $timeout = $self ? $self->{connect_timeout} : 0.25;
@@ -284,5 +287,4 @@
     select($old);
 
-    $sock_map{$sock} = $host;
     $cache_sock{$host} = $sock;
 
Index: /trunk/api/perl/ChangeLog
===================================================================
--- /trunk/api/perl/ChangeLog (revision 798)
+++ /trunk/api/perl/ChangeLog (revision 805)
@@ -1,2 +1,6 @@
+	* Reconnects to a dead connection shouldn't happen every time when the
+	  connection has never succeded. Apply the dead timeout to sockets that
+	  never even came up. Add a test.
+
 	* Warn when trying to put undef values into memcache.
 	  (Henry Lyne <hlyne@livejournalinc.com>)
