Skip Menu |

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

Report information
The Basics
Id: 16324
Status: resolved
Priority: 0/
Queue: Cache-Memcached

People
Owner: Nobody in particular
Requestors: martin [...] neoreality.com
Cc:
AdminCc:

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



Subject: Bad filehandle error with Devel::Profile
A simple script to set and get a value in memcached, which works normally, fails with an error when used with -d:Profile to profile the script with the Devel::Profile CPAN module. The error is produced from one of the IO or Socket modules (Carp is used so the error says it is from Devel::Profile): $ perl memcached.pl 100 $ perl -d:Profile memcached.pl Bad filehandle: Sock_127.0.0.1:11211 at /usr/lib/perl5/site_perl/5.8.0/Devel/Profile.pm line 133. memcached.pl test script follows: #!/usr/bin/perl use strict; use warnings; use Cache::Memcached; my $memd = new Cache::Memcached { 'servers' => [ '127.0.0.1:11211' ], 'debug' => 0, 'compress_threshold' => 10_000, }; profile_me(); sub profile_me { $memd->set('TEST', 100); print $memd->get('TEST'), "\n"; } __END__ The attached diff changes one line in the Cache::Memcached module that generates the socket handle name to include the package name, which seems to placate Devel::Profile, and the test script then runs normally, plus you get your "prof.out" profile output file as expected. - Martin Flack
--- Memcached.pm.orig 2005-12-06 21:30:24.000000000 +0000 +++ Memcached.pm.mod 2005-12-06 21:30:29.000000000 +0000 @@ -215,7 +215,7 @@ my ($ip, $port) = $host =~ /(.*):(\d+)/; return undef if $host_dead{$host} && $host_dead{$host} > $now; - my $sock = "Sock_$host"; + my $sock = __PACKAGE__."::Sock_$host"; my $connected = 0; my $sin;
From: Martin Flack
Actually you may need to make edits elsewhere that reference 'Sock_'. This patch may be closer to a solution. - Martin Flack
--- Memcached.pm.orig 2005-12-06 22:06:31.000000000 +0000 +++ Memcached.pm.mod 2005-12-06 22:05:47.000000000 +0000 @@ -47,6 +47,7 @@ my $PROTO_TCP; our $SOCK_TIMEOUT = 2.6; # default timeout in seconds +our $SOCK_HANDLE_PREFIX = __PACKAGE__.'::Sock_'; # socket handle prefix is followed by IP and port sub new { my Cache::Memcached $self = shift; @@ -146,7 +147,7 @@ sub _dead_sock { my ($sock, $ret, $dead_for) = @_; - if ($sock =~ /^Sock_(.+?):(\d+)$/) { + if ($sock =~ /^$SOCK_HANDLE_PREFIX(.+?):(\d+)$/) { my $now = time(); my ($ip, $port) = ($1, $2); my $host = "$ip:$port"; @@ -159,7 +160,7 @@ sub _close_sock { my ($sock) = @_; - if ($sock =~ /^Sock_(.+?):(\d+)$/) { + if ($sock =~ /^$SOCK_HANDLE_PREFIX(.+?):(\d+)$/) { my ($ip, $port) = ($1, $2); my $host = "$ip:$port"; close $sock; @@ -215,7 +216,7 @@ my ($ip, $port) = $host =~ /(.*):(\d+)/; return undef if $host_dead{$host} && $host_dead{$host} > $now; - my $sock = "Sock_$host"; + my $sock = $SOCK_HANDLE_PREFIX.$host; my $connected = 0; my $sin;
I can't really tell if this is relevant, sorry :( Patch from way before I was involved, at least :) Closing this out, since Devel::NYTProf seems usable with it.