Skip Menu |

This queue is for tickets about the PID-File CPAN distribution.

Report information
The Basics
Id: 79161
Status: resolved
Priority: 0/
Queue: PID-File

People
Owner: Nobody in particular
Requestors: holger [...] loomsday.co.nz
Cc:
AdminCc:

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



Subject: Can't call method "remove" on an undefined value
Date: Thu, 23 Aug 2012 22:01:20 +1200
To: bug-pid-file [...] rt.cpan.org
From: Holger Jahn <holger [...] loomsday.co.nz>
Hi Rob, We have been scratching our collective heads here for a while, since we always got greeted with the funny error message below: (in cleanup) Can't call method "remove" on an undefined value at /usr/local/perl2exe/perl5/lib/site_perl/5.10.0/PID/File.pm line 322 during global destruction. This message is thrown when we were calling to call the "guard" method on a global variable when the script is exiting, like so: use PID::File; my $pid_file; sub make_pid_file { $pid_file = PID::File->new; $pid_file->file('pidfile'); $pid_file->create; $pid_file->guard if $pid_file; print "pidfile created $$\n"; system("ls -l pidfile"); } make_pid_file(); system("ls -l pidfile"); exit; When we kept the scope local, i.e. with "my $pid_file" inside the function, then the error is not thrown, but the PID file is removed when the functions returns to its caller. After a while, I figured that PID::File started working correctly after changing line number 337 in PID/File.pm, like so: $self->remove; # $self->{ guard }->(); It would be great if you could have another look at the DESTROY function and see if my patch makes any sense. Many thanks & Kind regards, Holger
Thanks Holgar, I'll start looking into this today for you. Cheers, Rob
Subject: Re: [rt.cpan.org #79161] Can't call method "remove" on an undefined value
Date: Thu, 23 Aug 2012 23:29:46 +1200
To: bug-PID-File [...] rt.cpan.org
From: Holger Jahn <holger [...] loomsday.co.nz>
Excellent, thanks Rob! Cheers, Holger On 08/23/2012 11:09 PM, Rob Brown via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > Thanks Holgar, > > I'll start looking into this today for you. > > Cheers, > Rob > > > >
hmmm, I've just re-created your script, with the global var, and ran it, with no problems on 5.14.2 [rob@intelcompute perl]$ ./pid-file.pl pidfile created 2382 -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile [rob@intelcompute perl]$ #!/usr/bin/env perl # use PID::File; my $pid_file; sub make_pid_file { $pid_file = PID::File->new; $pid_file->file('pidfile'); $pid_file->create; $pid_file->guard if $pid_file; print "pidfile created $$\n"; system("ls -l pidfile"); } make_pid_file(); system("ls -l pidfile"); exit; I'm just building 5.10.0 to see if it's an issue specific to a version - I would've spotted that error with the unit tests and my own testing, so was a bit surprised by it. Cheers, Rob On Thu Aug 23 07:09:32 2012, CAGAO wrote: Show quoted text
> Thanks Holgar, > > I'll start looking into this today for you. > > Cheers, > Rob > > >
Yup, it's a problem on 5.10.0, let me investigate further... On Thu Aug 23 07:43:21 2012, CAGAO wrote: Show quoted text
> hmmm, I've just re-created your script, with the global var, and ran
it, Show quoted text
> with no problems on 5.14.2 > > [rob@intelcompute perl]$ ./pid-file.pl > pidfile created 2382 > -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile > -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile > [rob@intelcompute perl]$ > > > #!/usr/bin/env perl > # > use PID::File; > my $pid_file; > > sub make_pid_file { > > $pid_file = PID::File->new; > $pid_file->file('pidfile'); > > $pid_file->create; > $pid_file->guard if $pid_file; > print "pidfile created $$\n"; > > system("ls -l pidfile"); > } > > make_pid_file(); > system("ls -l pidfile"); > exit; > > I'm just building 5.10.0 to see if it's an issue specific to a version
- Show quoted text
> I would've spotted that error with the unit tests and my own testing,
so Show quoted text
> was a bit surprised by it. > > Cheers, > Rob > > > > On Thu Aug 23 07:09:32 2012, CAGAO wrote:
> > Thanks Holgar, > > > > I'll start looking into this today for you. > > > > Cheers, > > Rob > > > > > >
> >
Subject: Re: [rt.cpan.org #79161] Can't call method "remove" on an undefined value
Date: Fri, 24 Aug 2012 00:30:01 +1200
To: bug-PID-File [...] rt.cpan.org
From: Holger Jahn <holger [...] loomsday.co.nz>
Thanks, Rob. Yes, we are still using perl 5.10. Hope this can be fixed. Otherwise, we would need to update our entire Perl infrastructure (we are compiling for a bunch of different platforms). Cheers, Holger On 08/23/2012 11:54 PM, Rob Brown via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > Yup, it's a problem on 5.10.0, let me investigate further... > > > > On Thu Aug 23 07:43:21 2012, CAGAO wrote:
>> hmmm, I've just re-created your script, with the global var, and ran
> it,
>> with no problems on 5.14.2 >> >> [rob@intelcompute perl]$ ./pid-file.pl >> pidfile created 2382 >> -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile >> -rw-rw-r-- 1 rob rob 4 Aug 23 12:39 pidfile >> [rob@intelcompute perl]$ >> >> >> #!/usr/bin/env perl >> # >> use PID::File; >> my $pid_file; >> >> sub make_pid_file { >> >> $pid_file = PID::File->new; >> $pid_file->file('pidfile'); >> >> $pid_file->create; >> $pid_file->guard if $pid_file; >> print "pidfile created $$\n"; >> >> system("ls -l pidfile"); >> } >> >> make_pid_file(); >> system("ls -l pidfile"); >> exit; >> >> I'm just building 5.10.0 to see if it's an issue specific to a version
> -
>> I would've spotted that error with the unit tests and my own testing,
> so
>> was a bit surprised by it. >> >> Cheers, >> Rob >> >> >> >> On Thu Aug 23 07:09:32 2012, CAGAO wrote:
>>> Thanks Holgar, >>> >>> I'll start looking into this today for you. >>> >>> Cheers, >>> Rob >>> >>> >>>
>> >>
> > >
Aye understandable, well done on even being on 5.10 :) Will let you know how I get on, sure I'll have a fix...
Subject: Re: [rt.cpan.org #79161] Can't call method "remove" on an undefined value
Date: Fri, 24 Aug 2012 00:38:42 +1200
To: bug-PID-File [...] rt.cpan.org
From: Holger Jahn <holger [...] loomsday.co.nz>
Eventually, we will go down the 5.14 path... we are just a bit laz..., err... reluctant in doing that right away. ;-) On 08/24/2012 12:32 AM, Rob Brown via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > Aye understandable, well done on even being on 5.10 :) > > Will let you know how I get on, sure I'll have a fix... >
OK, this is a strange issue which I'll have to dig into more. But I do have a work around, and generally a better way of doing things anyway. Don't have make_pid_file() access global variables, instead, return back the pid file object as per the following example - this should solve all your problems. The bug was still actually seen on 5.14.2 but just without the error, ie, the pidfile remains. #!/usr/bin/env perl use strict; use warnings; use PID::File; sub make_pid_file { my $pid_file = PID::File->new; $pid_file->file('pidfile'); $pid_file->create; $pid_file->guard if $pid_file; print "pidfile created $$\n"; system("ls -l pidfile"); return $pid_file; } my $pid_file = make_pid_file(); system("ls -l pidfile"); exit; On Thu Aug 23 08:38:52 2012, holger@loomsday.co.nz wrote: Show quoted text
> Eventually, we will go down the 5.14 path... we are just a bit laz..., > err... reluctant in doing that right away. ;-) > > On 08/24/2012 12:32 AM, Rob Brown via RT wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > > > Aye understandable, well done on even being on 5.10 :) > > > > Will let you know how I get on, sure I'll have a fix... > >
>
So, the issue was down to the fact that you had a sub routine closing over the $pid_file variable, and since subs are global, the object didn't go out of scope until the end of everything, ie, when the sub finally goes out of scope, and by that time, the object had gone too. The wonderful world of garbage collection. Issue fixed in PID-File-0.31, should be available on CPAN in a few hours. Happy days! :)
Subject: Re: [rt.cpan.org #79161] Can't call method "remove" on an undefined value
Date: Fri, 24 Aug 2012 13:09:24 +1200
To: bug-PID-File [...] rt.cpan.org
From: Holger Jahn <holger [...] loomsday.co.nz>
Thanks again, Rob, for taking great care with so little response time. Much appreciated! :-) Spring greetings from Auckland/NZ, Holger On 08/24/2012 01:55 AM, Rob Brown via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > So, the issue was down to the fact that you had a sub routine closing > over the $pid_file variable, and since subs are global, the object didn't > go out of scope until the end of everything, ie, when the sub finally > goes out of scope, and by that time, the object had gone too. > > The wonderful world of garbage collection. > > Issue fixed in PID-File-0.31, should be available on CPAN in a few hours. > > Happy days! :) >
Hi Holger, No problem, I know how frustrating it can be raising bugs with cpan distros sometimes and not have them looked at for weeks, months, or even years. Cheers, Rob On Thu Aug 23 21:09:37 2012, holger@loomsday.co.nz wrote: Show quoted text
> Thanks again, Rob, for taking great care with so little response time. > > Much appreciated! :-) > > Spring greetings from Auckland/NZ, > Holger > > On 08/24/2012 01:55 AM, Rob Brown via RT wrote:
> > <URL: https://rt.cpan.org/Ticket/Display.html?id=79161 > > > > > So, the issue was down to the fact that you had a sub routine
closing Show quoted text
> > over the $pid_file variable, and since subs are global, the object
didn't Show quoted text
> > go out of scope until the end of everything, ie, when the sub
finally Show quoted text
> > goes out of scope, and by that time, the object had gone too. > > > > The wonderful world of garbage collection. > > > > Issue fixed in PID-File-0.31, should be available on CPAN in a few
hours. Show quoted text
> > > > Happy days! :) > >
>