Infinite loop in perl Carp module

We have code that catches the exception, writes the message, and then calls Carp::longmess to get the stack.

Thus, a simplified view of what we are doing is:

 eval { <some SOAP::Lite stuff> }; if( my $err = $@ ) { logwrite( "Caught Error: $err" ); } 

The logwrite function is essentially:

 sub logwrite($) { my $msg = $_[0]; my($pkg,$fil,$lin)=caller; my $timestamp = POSIX::strftime(...); print STDERR "$timestamp $fil/$lin $msg\n"; print STDERR "$timestamp $fil/$lin Stack trace:\n" . Carp::longmess . "\n"; } 

But in the log I see:

 20111030 Module.pm/42 Caught Error: at line Use of uninitialized value in caller at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 22. Use of uninitialized value in string eq at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 91. Use of uninitialized value in numeric lt (<) at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 200. Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 55. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 55. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 142. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 142. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 142. Use of uninitialized value in concatenation (.) or string at /usr/lib/perl5/5.8.8/Carp/Heavy.pm line 142. ... 

And this sequence of warnings from the Carp/Heavy.pm repeated over and over indefinitely, blowing out the login. Therefore, we end up killing him. These warnings remind you that they are called by calling Carp::longmess . Another interesting thing here is the $@ variable, which looks like at . It is like at added by die, but no actual error message or line number.

Has anyone seen this before or have any idea what is going on with the Carp package? This is rare, but several months have passed several dozen times, and we have hundreds of tasks that work every day.

+4
source share
2 answers

I understand that this does not answer your real question, but., Since, apparently, $msg eq 'at line ' in this case, perhaps you should just work around the problem by attaching unless $msg eq 'at line ' to the end of the instruction print ... Carp::longmess ... ? (I mean, unless someone offers a real solution.)

0
source

Your code works for me on perl v5.10.1, with Carp.pm version 1.11.

However, note that this is not what you expect: the backtrace created by longmess will show where the logwrite function was called logwrite , and not where the actual error occurred inside eval .

+1
source

Source: https://habr.com/ru/post/1379058/


All Articles