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

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

Thread Next
Animator via RT
April 27, 2008 05:30
[perl #52000] Warn/abort on attempted perl exit
Message ID:
On Fri Mar 21 15:51:56 2008, wrote:
> This is a bug report for perl from,
> 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.


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

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

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

1: main /tmp/ 13 main::__ANON__ 1    0 
2: main /tmp/ 12 main::s3 1    0 
3: main /tmp/ 11 main::s2 1    0 
4: main /tmp/ 15 main::s1 1    0 

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

Kind regards,


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About