toddr / Net-Daemon

Read-only release history for Net-Daemon
http://metacpan.org/release/Net-Daemon
0 stars 0 forks source link

Net::Daemon fails if 'use threads::shared' precedes use Net::Daemon [rt.cpan.org #81640] #18

Closed toddr closed 3 years ago

toddr commented 3 years ago

Migrated from rt.cpan.org#81640 (status was 'open')

Requestors:

Attachments:

From bozziebear@hotmail.com on 2012-12-02 11:00:11 :

Net::Daemon seems to fail if threads::shared has been loaded prior to
the "use Net::Daemon;" call. The attached file is your
Net::Daemon/t/base.t test case plus:
 use threads;
 use threads::shared;

Here's what happens on my system:
----------
perl NetDaemon-base.pl
1..1
Type of arg 1 to threads::shared::share must be one of [$@%] (not single
ref constructor) at /usr/lib/perl5/vendor_perl/5.16.0/Net/Daemon.pm line
54, near "$Net::Daemon::RegExpLock) "
BEGIN not safe after errors--compilation aborted at
/usr/lib/perl5/vendor_perl/5.16.0/Net/Daemon.pm line 56.
Compilation failed in require at NetDaemon-base.pl line 9.
BEGIN failed--compilation aborted at NetDaemon-base.pl line 9.
not ok 1

% uname -a
Linux sr1650nx 3.4.11-2.16-desktop #1 SMP PREEMPT Wed Sep 26 17:05:00
UTC 2012 (259fc87) x86_64 x86_64 x86_64 GNU/Linux
%pmvers Net::Daemon threads threads::shared
Net::Daemon: 0.48
threads: 1.86
threads::shared: 1.4
% perl -v
This is perl 5, version 16, subversion 0 (v5.16.0) built for
x86_64-linux-thread-multi
----------

To get both original and modified base.t and my own application working
in my particular Perl environment, I made the following edits to Daemon.pm:

41,44c41,42
< if ($this_is_510) {
<     eval { require threads; };
<     eval { require threads::shared; };
< }
---
> use threads;
> use threads::shared;
54c52
< threads::shared::share(\$Net::Daemon::RegExpLock) if $this_is_510;
---
> threads::shared::share($Net::Daemon::RegExpLock) if $this_is_510;

The threads::shared::share() call now matches its documentation, so that
change seems right, but I don't understand the subtleties of the
"this_is_510" test and its dummy share.

Thanks for looking at this.

From bozziebear@hotmail.com on 2012-12-02 11:03:24 :

Corrected attachment.
Sorry - I uploaded the test case with the key line commented out.

From m.nooning@comcast.net on 2012-12-03 19:08:23 :

Your change works on my Windows XP, Perl 5.16, too.

I am going to test it on a Windows machine with an earlier Perl, and an 
Linux machine with an earlier Perl.

If everything works I will incorporate the change.  If not, but it works 
for 5.14, I will specify that 5.14 and above be used.  5.14 had some 
nice changes.

 >but I don't understand the subtleties of the "this_is_510" test and 
its dummy share.
I do not, either.  It was another contributor who came up with that.  It 
caused Net::Daemon to work for everything at the time so I was quite 
happy with it.  The original author Jochen Wiedmann passed his modules 
to me in 2007 and I have been maintaining them since.  I have been 
successful mainly through the contributions of others, such as the one 
you just gave me.

Thank you very, very much.

It might  be a week or so before I am finished.

On 12/2/2012 6:03 AM, Tom via RT wrote:

From m.nooning@comcast.net on 2012-12-05 16:50:37 :

I cannot get this to work on Perl 5.14.2.  I wonder what happened with 
5.14.2?  It works on
my Perl 5.16!.  They are both Windows XP machines.  It is freeing memory 
to the wrong pool, so there is a threads problem.

Both machines have their respective Perls compiled for threads. Hmmm.
I am thinking of putting in your changes anyway.  Perhaps this weekend.

From bozziebear@hotmail.com on 2012-12-05 22:53:59 :

I will go back through my test cases when I started investigating this.
At the time, I just assumed it was a bug in my code, so I may have
overlooked some clue that will help us understand what is going on here.

Also, I can reboot into an older distro that has perl 5.12 and see what
results I get there.

-----Original Message-----
From: Malcolm Nooning via RT [mailto:bug-Net-Daemon@rt.cpan.org] 
Sent: Wednesday, December 05, 2012 8:51 AM
To: bozziebear@hotmail.com
Subject: Re: [rt.cpan.org #81640] Net::Daemon fails if 'use threads::shared'
precedes use Net::Daemon

<URL: https://rt.cpan.org/Ticket/Display.html?id=81640 >

I cannot get this to work on Perl 5.14.2.  I wonder what happened with
5.14.2?  It works on my Perl 5.16!.  They are both Windows XP machines.  It
is freeing memory to the wrong pool, so there is a threads problem.

Both machines have their respective Perls compiled for threads. Hmmm.
I am thinking of putting in your changes anyway.  Perhaps this weekend.

From m.nooning@comcast.net on 2012-12-06 17:13:32 :

That would be really great, Tom.
On 12/5/2012 5:54 PM, Tom via RT wrote:
> time, I just assumed it was a bug in my c

From bozziebear@hotmail.com on 2012-12-11 00:26:09 :

Hi Malcolm,

This code passes base.t with and w/o the extra "use" statements and still
uses conditional loading:

package Net::Daemon;
use Module::Load::Conditional qw(can_load);

@Net::Daemon::ISA = qw(Net::Daemon::Log);
$Net::Daemon::VERSION = '0.48';
$Net::Daemon::RegExpLock = 1;

# Dummy share() in case we're >= 5.10. If we are, require/import of
# threads::shared will replace it appropriately.
if ($^V ge v5.10.0) {
    can_load(modules => {"threads::shared" => undef})
    or die "Failed to load module 'threads::shared'";
    # Regexps aren't thread safe, as of 5.00502?
    # (See the test script regexp-threads.):
    threads::shared::share($Net::Daemon::RegExpLock);
}

use vars qw($exit);
etc ...

Besides re-ordering the code for better readability, the only functional
change I made is replacing the 2 "evals" with the
Module::Load::Conditional::can_load() call. Thus I hope it will behave as
before on pre-5.10 versions of Perl, but since you saw it fail on 5.14, I'm
not making any predictions!

I think all of Net::Daemon's other dependencies are part of the Perl core
whereas Module::Load::Conditional is not, so that may be an objection. The
can_load() method has existed since the earliest CPAN version of M::L::C
(0.02 from 2003), making it more likely that pre-5.10 Perl/Net::Daemon
installations can find a compatible version if they can't use the current
release.

Regards,
Tom
toddr commented 3 years ago

This appears to have been fixed with the 0.44 release: 5b56cc67