develooper Front page | perl.perl5.porters | Postings from April 2008

[perl #52000] Warn/abort on attempted perl exit

Thread Next
From:
Animator via RT
Date:
April 27, 2008 05:30
Subject:
[perl #52000] Warn/abort on attempted perl exit
Message ID:
rt-3.6.HEAD-7021-1209210403-1171.52000-15-0@perl.org
On Fri Mar 21 15:51:56 2008, jgmyers@proofpoint.com wrote:
> This is a bug report for perl from jgmyers@pong.us.proofpoint.com,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> I have a multithreaded C++ server which embeds Perl and has a handful
> of PerlInterpreter objects.  One of the problems is that occasionally
> Perl or some CPAN module will attempt to exit.  In a multithreaded
> process, calling exit() results in bad behavior--the thread will run
> all of the static destructors and atexit handlers and then terminate,
> leaving the remaining threads running, using the already-destructed
> and/or freed static data.  The process will usually dump core some
> time later, possibly after having corrupted persistent data.
> 
> Clearing the PERL_EXIT_EXPECTED bit doesn't quite work right, for
> reasons which I'll mention in a separate bug.  One of the main
> problems with it is that perl unwinds the stack a bit before even
> testing for PERL_EXIT_EXPECTED, so there is no way I can find out
> where in all that perl code the exit came from.
> 
> Below is a patch that adds a PERL_EXIT_WARN feature for embedders.
> This allows one to obtain, through a __WARN__ handler, a perl stack
> trace pointing to the code that attempted to exit.
> 
> Also is a PERL_EXIT_ABORT feature primarily intended to prevent
> infinite recursion through the PERL_EXIT_WARN feature.  It is also
> useful separately to allow a clean abort of the process instead of
> attempting to unwind the stack.
>

Hello,

Did you also try with overriding the built-in exit function?

#!/usr/bin/perl -l
BEGIN {
  *CORE::GLOBAL::exit = sub {
    my $i=0;
    while (my @z = caller($i++)) {
      print "$i: @z";
    }
    CORE::exit(@_);
  }
}

sub s1 { s2(); }
sub s2 { s3(); };
sub s3 { exit(); }

s1();
__END__
1: main /tmp/52000.pl 13 main::__ANON__ 1    0 
2: main /tmp/52000.pl 12 main::s3 1    0 
3: main /tmp/52000.pl 11 main::s2 1    0 
4: main /tmp/52000.pl 15 main::s1 1    0 

This (of course) won't stop someone from exiting by calling CORE::exit.


Kind regards,

Bram


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About