Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by gmargo (Hermit)
on Dec 20, 2009 at 23:22 UTC ( [id://813655]=note: print w/replies, xml ) Need Help??


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

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}; + } +} +
  • Comment on Re^3: panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.
  • Download Code

Replies are listed 'Best First'.
Re^4: panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.
by faber (Acolyte) on Dec 22, 2009 at 17:46 UTC
    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
      Did you try the suggested solution? Did it work?

      thanks

      Clint

Re^4: panic: attempt to copy freed scalar 802e7e120 to 802e7e708 at Server.pm line 380.
by faber (Acolyte) on Feb 04, 2011 at 23:59 UTC
    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://813655]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found