Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Disappearing fatal errors and die() with mod_perl2

by Farenji (Novice)
on Jul 31, 2009 at 15:10 UTC ( [id://784916]=perlquestion: print w/replies, xml ) Need Help??

Farenji has asked for the wisdom of the Perl Monks concerning the following question:

I hope someone can shed some light on the following strange problem:

I'm using perl5.10 with mod_perl2 (ModPerl::Registry) / apache2, with a fairly big perl application consisting of quite a few own modules and a bunch of CPAN modules. Normally, when I do a die('whatever') in the code, or if there's a fatal error, this shows up in the error log like:

[Fri Jul 31 16:18:58 2009] [error] whatever at module.pm line 123

Lately I noticed that in certain cases, these errors disappear in some black hole. Don't know what happens with it and why. For example, this works fine:

#!/usr/bin/perl use strict; use Foo; die('this will appear in the error log like expected');
But the following will give nothing at all in the logs:
#!/usr/bin/perl use strict; use Foo; # here, something happens that messes up the die handler? my $foo = Foo->new(); die('this will NOT appear in the error log at all');

The following DOES give errors in the log:

#!/usr/bin/perl use strict; use Foo; # here, something happens that messes up the die handler? my $foo = Foo->new(); # but this apparently fixes it: undef $foo; die('this DOES appear in the error log');

Unfortunately, the Foo module is company confidential so I cannot post the code of this module here. I checked the entire module, including all (direct and indirect) dependencies, but so far I haven't found anything suspicious. There's no weird perl magic going on, as far as I can tell. All scripts are CGI compatible so no specific mod_perl directives. There are a lot of modules "use"d however so it's like looking for a needle in the haystack..

This problem doesn't turn up on the command line. Nor does it when I use plain old CGI. Then everything works fine. So I figure it's got something to do with mod_perl.

I tried changing the die signal handler, I tried all of the following, but without the desired effect: (I also tried it without "local", no change)

local $SIG{__DIE__} = ''; # no effect local $SIG{__DIE__} = 'DEFAULT'; # no effect # this gives a warning in the error log, no error local $SIG{__DIE__} = sub { warn @_ }; # this has no effect, nothing at all in the logs: local $SIG{__DIE__} = sub { die @_ };

For debugging purposes, redirecting the die to a warn is a viable workaround, but the application also contains a SOAP::Lite server, and in the server code, I use

die SOAP::Fault->new(..);
to throw Soap errors. The problem is that this doesn't work in cases described here; then, an empty Soap message is returned. That's a show stopper.

ATM, I don't know anymore where to look and what to look for, to solve this. Could anyone point me in a direction, or give me some suggestions I might try to solve this?

Replies are listed 'Best First'.
Re: Disappearing fatal errors and die() with mod_perl2
by Bloodnok (Vicar) on Jul 31, 2009 at 15:49 UTC
    It looks/sounds to me like the die handler i.e. $SIG{__DIE__}, might be/is being modified in/by the Foo constructor - which is, IMO, why your changes in the use'ing code have no effect and undef'ing the object clears the problem.

    I would suggest either:

    • Using a binary chop method commenting out chunks of Foo until such time as the problem goes away and then work backwards from there or...
    • Find the minimal representative code that reproduces the problem
    Then i.e having done either/both of the above, come back and ask again (by updating your node) - with any luck and a following wind, by that time, you might even have identified the problem for yourself.

    A user level that continues to overstate my experience :-))

      Thanks for your reply. I got so far that a messed up/redefined die handler could be the problem. It's still one of my main hypotheses. But I cannot explain why:

      • (locally) re-defining/resetting the die handler using $SIG{__DIE__} does not solve the issue - it should if that's the problem, shouldnt it?
      • the issue only occurs under mod_perl, not in CLI or with CGI. That suggests the problem could be outside my code.

      Of course I did my share of eliminating / commenting out parts, got me a bit further, but it takes LONG as there's hundreds of modules, many thousands line of code to go through. I haven't stop looking yet and will continue my quest for the solution, but I was hoping someone else encountered a similar issue before.

        ...(locally) re-defining/resetting the die handler using $SIG{__DIE__} does not solve the issue... : nor would it - consider tst.pl and Foo.pm defined as:
        #! /usr/bin/env perl use warnings; use strict; use Foo; die "Died here";
        package Foo; local $SIG{__DIE__} = sub { print "Caught in " . __PACKAGE }; sub _die { die }; 1;
        When run, tst.pl produces
        $> perl tst.pl Died here at tst.pl line 7.
        As expected ... by me anyway, since the handler has only been locally re-defined at the lower-level i.e. in the scope of Foo, leaving the handler unchanged at the upper/calling level.

        As to your latter question, sadly, I have no experience with mod_perl, so I'm afraid, have nothing to contribute :-((

        A user level that continues to overstate my experience :-))
Re: Disappearing fatal errors and die() with mod_perl2
by perrin (Chancellor) on Jul 31, 2009 at 21:41 UTC
    I was going to guess that your code is messing with the STDERR filehandle, but if warn shows up that can't be it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (9)
As of 2024-04-18 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found