Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.

by gmargo (Hermit)
on Dec 19, 2009 at 14:50 UTC ( [id://813521]=note: print w/replies, xml ) Need Help??


in reply to panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.

I took a quick look at your Ext::Fork module.

The only thing that comes to mind at the moment is your SIGCHLD signal handler. I would avoid modifying the cidlist hash within the handler. Just mark the process as done somehow and clean it up outside the handler. Then it can't possibly conflict with the server reading the hash in rfork_list_children(). I would also avoid decrementing the children counter in the handler.

Replies are listed 'Best First'.
Re^2: panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.
by Anonymous Monk on Dec 20, 2009 at 18:56 UTC
    Ok so I can move the counter out of there, but how do you propose I move the hash management out of there? What other mechanism do you suggest I use to trap child processes which are exiting?

      I would just mark the process done by zeroing the hash value. Then at strategic points in the parent-side code I would "clean up" the list.

      Here is a diff to your code that implements that change. Mind you though, it is completely untested so there may still be gaping holes.

      --- Ext/Fork.pm.00 2009-12-19 06:00:59.000000000 -0800 +++ Ext/Fork.pm 2009-12-20 15:16:22.000000000 -0800 @@ -109,6 +109,7 @@ } while(1){ + rfork_cleanup(); if($Ext::Fork::POOL->{children} < $Ext::Fork::POOL->{max_chil +dren}){ last; } @@ -145,6 +146,7 @@ if($Ext::Fork::POOL->{has_children} && !$Ext::Fork::POOL->{nonblo +cking}){ while(1){ + rfork_cleanup(); last if !$Ext::Fork::POOL->{children}; if($Ext::Fork::has_thr){ rfork_usleep(500); @@ -195,8 +197,7 @@ sub _sigchld { while((my $p = waitpid(-1, WNOHANG)) > 0){ - delete $Ext::Fork::POOL->{cidlist}->{$p}; - $Ext::Fork::POOL->{children} -- if $Ext::Fork::POOL->{childre +n}; + $Ext::Fork::POOL->{cidlist}->{$p} = 0; # mark process as d +one } # self reference @@ -243,6 +244,7 @@ return 1 if $Ext::Fork::POOL->{nonblocking}; while(1){ + rfork_cleanup(); last if !$Ext::Fork::POOL->{children}; if($Ext::Fork::has_thr){ @@ -262,6 +264,7 @@ =cut sub rfork_active_children { + rfork_cleanup(); return ($Ext::Fork::POOL->{children} ? $Ext::Fork::POOL->{childre +n} : 0); } @@ -391,6 +394,7 @@ sub rfork_kill_children { my $sig = $_[0]; + rfork_cleanup(); if(!$sig){ $sig = 'TERM'; } @@ -410,6 +414,7 @@ sub rfork_list_children { my ($use_hash) = @_; + rfork_cleanup(); if(!$Ext::Fork::POOL->{cidlist}){ return; @@ -432,6 +437,7 @@ sub rfork_child_dob { my $pid = $_[0]; + rfork_cleanup(); if($Ext::Fork::POOL->{cidlist}->{$pid}){ return $Ext::Fork::POOL->{cidlist}->{$pid}; } else { @@ -439,4 +445,21 @@ } } +=head2 rfork_cleanup() + +Perform delayed list cleanup. + +=cut + +sub rfork_cleanup { + my @deadpids = + grep { $Ext::Fork::POOL->{cidlist}->{$_} == 0 } + keys %{ $Ext::Fork::POOL->{cidlist} }; + foreach (@deadpids) + { + delete $Ext::Fork::POOL->{cidlist}->{$_}; + $Ext::Fork::POOL->{children} -- if $Ext::Fork::POOL->{childre +n}; + } +} +
        Ah yes, What a great idea. So i'll give this a try, though it's still modifying cidlist hash, thogh hopefully without removing the entry it might not panic. In any event do you see any value of submitting this module to CPAN or does this seem like more reinventing of the wheel? If yes - suggested location? -cf
        Hi sorry for the late update, I should note that this fix did correct the panic issue. -cf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://813521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found