Skip Menu |

This queue is for tickets about the Cache-Memcached CPAN distribution.

Report information
The Basics
Id: 59594
Status: open
Priority: 0/
Queue: Cache-Memcached

People
Owner: Nobody in particular
Requestors: bobtfish [...] bobtfish.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Useless error message if you use a bad hostname in server list.
omni ~ $ perl -MCache::Memcached -e'Cache::Memcached->new({servers => ["does.not.exist:11211"]})->set("foo", "bar")' Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4 at /usr/lib/perl/5.10/Socket.pm line 214. This is pretty spectacularly unhelpful. As per the rest of the memcache client, it would be better if the bad server was just ignored / not connected to (and the connect fail callback if defined was called). Patch attached which does this.
Subject: Cache-Memcached-badhostname-nodie.patch
diff --git a/lib/Cache/Memcached.pm b/lib/Cache/Memcached.pm index c1bf67b..fbb462c 100644 --- a/lib/Cache/Memcached.pm +++ b/lib/Cache/Memcached.pm @@ -261,10 +261,12 @@ sub sock_to_host { # (host) #why is this public? I wouldn't have to worry about } else { socket($sock, PF_INET, SOCK_STREAM, $proto); $sock_map{$sock} = $host; - $sin = Socket::sockaddr_in($port, Socket::inet_aton($prefip)); + my $aton_ip = Socket::inet_aton($prefip); + $sin = Socket::sockaddr_in($port, $aton_ip) + if $aton_ip; } - if (_connect_sock($sock,$sin,$self->{connect_timeout})) { + if ($sin && _connect_sock($sock,$sin,$self->{connect_timeout})) { $connected = 1; } else { if (my $cb = $self->{cb_connect_fail}) { @@ -285,11 +287,13 @@ sub sock_to_host { # (host) #why is this public? I wouldn't have to worry about } else { socket($sock, PF_INET, SOCK_STREAM, $proto); $sock_map{$sock} = $host; - $sin = Socket::sockaddr_in($port, Socket::inet_aton($ip)); + my $aton_ip = Socket::inet_aton($ip); + $sin = Socket::sockaddr_in($port, $aton_ip) + if $aton_ip; } my $timeout = $self ? $self->{connect_timeout} : 0.25; - unless (_connect_sock($sock, $sin, $timeout)) { + unless ($sin && _connect_sock($sock, $sin, $timeout)) { my $cb = $self ? $self->{cb_connect_fail} : undef; $cb->($ip) if $cb; return _dead_sock($self, $sock, undef, 20 + int(rand(10)));
I was about to report the same error, so +1 on this. The error message is very obscure as it stands: "Bad arg length for Socket::pack_sockaddr_in, length is 0, should be 4 at /usr/lib64/perl5/Socket.pm line 386." (version 1.28). If this patch is not accepted (along with soem doco to indicate how one could craft a callback to give more useful information), then perhaps catch this error and report to STDERR as "Invalid memcache host name %s"? At least it gives users a chance to spot which socket connection could be the suspect one causing an issue.
RT-Send-CC: matthias.nott [...] gmail.com
Hmm. 8.5 Years and this is still open. At least the patch also still works. This became relevant over here when I needed to have an option to run memcached in either a virtual machine, together with its client, or within a separate Docker image. Hence the connection would work like this: my $memd = new Cache::Memcached { 'servers' => ['127.0.0.1:11211', 'memcached:11211'], 'compress_threshold' => 10_000, }; The second part, 'memcached:11211', was attached and resolves if, and only if, the image is run as a Docker image. If running as a VM, the address will not resolve. When running as a docker image, the connection to localhost will just fail, as there is no memcached running on the local port. It will then gracefully take the oter option, memcached:11211. When running within a VM, where memcached is deployed alongside the application doing the code above, it should contend with the local memcached, but as it sees the other entry, it will fail with the error reported within this bug. As we optionally provide our application as a virtual machine (through Vagrant) and as a docker image, this is annoying, and hence thanks for having worked out that patch.