You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joel Gwynn <jo...@gmail.com> on 2007/01/21 18:05:44 UTC

Troubleshooting Apache2 Segfaults

I'm running mod_perl 2.0.2 (I think) on apache 2 on Debian Linux
2.6.9-023stab033.6

I've got a mod_perl application which segfaults on every 10th or so
requests.  Here's what I get in my error log:

[notice] child pid xxxx exit signal Segmentation fault (11)

How would I go about troubleshooting this?

Re: Troubleshooting Apache2 Segfaults

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jan 22, 2007, at 9:12 AM, Joel Gwynn wrote:

> Is DEBUG_USER_LOGIC shorthand for something?

No.

You just have to make your own (USER_LOGIC) debugging lines, to try  
and figure out where you're segfaulting.

The other option is this:
	http://search.cpan.org/~pgollucci/mod_perl-2.0.3/docs/devel/debug/ 
c.pod#Analyzing_Dumped_Core_Files

Which  can preclude you from rapidly addressing the problem.

normally I have from 2-20  debug flags and each one has multiple  
levels.  if there's ever an issue with a piece of code or a segfault,  
i can figure out what it is in a few requests with everything turned  
on, then bump up the level on the problematic functions.

If you're using any CPAN modules, chances are they have some debug  
flags in there that might be able to help.  the only time i've  
segfaulted has been with  bad calls to the mp API , dbi drivers that  
weren't compiled right, and bad cookies in earlier verisons of apreq.

If you have a trivial amount of debug code for your own application  
though, you can usually track down the cause of most problems in a  
matter of minutes.

// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
| SyndiClick.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      FindMeOn.com - The cure for Multiple Web Personality Disorder
|      Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -
|      RoadSound.com - Tools For Bands, Stuff For Fans
|      Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - - - - -



Re: Troubleshooting Apache2 Segfaults

Posted by Joel Gwynn <jo...@gmail.com>.
On 1/21/07, Jonathan Vanasco <jv...@2xlp.com> wrote:
>
> On Jan 21, 2007, at 12:05 PM, Joel Gwynn wrote:
>
> > I've got a mod_perl application which segfaults on every 10th or so
> > requests.  Here's what I get in my error log:
> >
> > [notice] child pid xxxx exit signal Segmentation fault (11)
> >
> > How would I go about troubleshooting this?
>
>
> toss a bunch of
>         DEBUG_USER_LOGIC && print STDERR "\nHere i am"
>
> lines where  you think the issue might happen.
>
> also have stuff like:
>         DEBUG_USER_LOGIC && debug_function( "message here" )
> lines around your functions too
>

Is DEBUG_USER_LOGIC shorthand for something?

Re: Troubleshooting Apache2 Segfaults

Posted by Jonathan Vanasco <jv...@2xlp.com>.
On Jan 21, 2007, at 12:05 PM, Joel Gwynn wrote:

> I've got a mod_perl application which segfaults on every 10th or so
> requests.  Here's what I get in my error log:
>
> [notice] child pid xxxx exit signal Segmentation fault (11)
>
> How would I go about troubleshooting this?


toss a bunch of
	DEBUG_USER_LOGIC && print STDERR "\nHere i am"

lines where  you think the issue might happen.

also have stuff like:
	DEBUG_USER_LOGIC && debug_function( "message here" )
lines around your functions too

then just set / unset your custom debug levels.  caller(1) helps  
too.  but you really need to build some user-defined debug logic into  
your app.






// Jonathan Vanasco

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -
| RoadSound.com - Tools For Bands, Stuff For Fans
| Collaborative Online Management And Syndication Tools
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
- - - - - - - - - - - - - - - -



Re: Troubleshooting Apache2 Segfaults

Posted by Perrin Harkins <ph...@gmail.com>.
On 1/24/07, Robert Landrum <rl...@aol.net> wrote:
> Perrin Harkins wrote:
> > My guess is that $self has a lifespan longer than one request, so you
> > are trying to use a $r object from a previous request.
>
> Would $r still be defined in that instance?

Yes.  What you're checking is that the reference is still defined, and
the reference still points to something, but the thing it points to is
no longer usable.

- Perrin

Re: Troubleshooting Apache2 Segfaults

Posted by Robert Landrum <rl...@aol.net>.
Perrin Harkins wrote:
> My guess is that $self has a lifespan longer than one request, so you
> are trying to use a $r object from a previous request.

Would $r still be defined in that instance?

Rob

Re: Troubleshooting Apache2 Segfaults

Posted by Perrin Harkins <ph...@gmail.com>.
On 1/24/07, Joel Gwynn <jo...@gmail.com> wrote:
> My understanding is that PerlSetVar is not a per-request directive.
> What am I missing?

You mean dir_config?  It's not per-request, but I'm guessing that $r
in your code is an Apache2::RequestRec object, which is per-request.
You have to call dir_config on an Apache2::RequestRec object because
it contains the specifics of which config section you are actually in
right now, and you can't keep that $r between requests.  You need to
get a new one every time.

- Perrin

Re: Troubleshooting Apache2 Segfaults

Posted by Joel Gwynn <jo...@gmail.com>.
On 1/24/07, Perrin Harkins <ph...@gmail.com> wrote:
> On 1/24/07, Joel Gwynn <jo...@gmail.com> wrote:
> > OK.  I replaced that line with a hard-coded file path, and now it's
> > looking much better.  So I guess it's something about the Request
> > object.
>
> My guess is that $self has a lifespan longer than one request, so you
> are trying to use a $r object from a previous request.
>
> - Perrin

My understanding is that PerlSetVar is not a per-request directive.
What am I missing?

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlSetVar_

Re: Troubleshooting Apache2 Segfaults

Posted by Perrin Harkins <ph...@gmail.com>.
On 1/24/07, Joel Gwynn <jo...@gmail.com> wrote:
> OK.  I replaced that line with a hard-coded file path, and now it's
> looking much better.  So I guess it's something about the Request
> object.

My guess is that $self has a lifespan longer than one request, so you
are trying to use a $r object from a previous request.

- Perrin

Re: Troubleshooting Apache2 Segfaults

Posted by Joel Gwynn <jo...@gmail.com>.
On 1/24/07, Joel Gwynn <jo...@gmail.com> wrote:
> On 1/24/07, Robert Landrum <rl...@aol.net> wrote:
> > Joel Gwynn wrote:
> > > Interesting.  I just might be doing that:
> > > $config_file = $self->param('r')->dir_config('CONFIG_FILE');
> > >
> > > In my <Directory> section, I have this:
> > >
> > > PerlSetVar CONFIG_FILE /projects/funnyr_dev/private/config.ini
> > >
> > > And of course I'm not using flock on that file.  Hmmm.
> >
> > Try changing that up...
> >
> > my $r = $self->param('r');
> > if(defined $r) {
> >    $config_file = $r->dir_config('CONFIG_FILE');
> > }
> > else {
> >    # handle no $r
> > }
> >
> > Give that a shot and see if it solves the problem.
>
> Thanks, but I'm already doing that, well actually I'm doing this:
>
> if($self->param('r')){
>  $config_file = $r->dir_config('CONFIG_FILE');
> }
>
> which should be the same, no?

OK.  I replaced that line with a hard-coded file path, and now it's
looking much better.  So I guess it's something about the Request
object.

Re: Troubleshooting Apache2 Segfaults

Posted by Joel Gwynn <jo...@gmail.com>.
On 1/24/07, Robert Landrum <rl...@aol.net> wrote:
> Joel Gwynn wrote:
> > Interesting.  I just might be doing that:
> > $config_file = $self->param('r')->dir_config('CONFIG_FILE');
> >
> > In my <Directory> section, I have this:
> >
> > PerlSetVar CONFIG_FILE /projects/funnyr_dev/private/config.ini
> >
> > And of course I'm not using flock on that file.  Hmmm.
>
> Try changing that up...
>
> my $r = $self->param('r');
> if(defined $r) {
>    $config_file = $r->dir_config('CONFIG_FILE');
> }
> else {
>    # handle no $r
> }
>
> Give that a shot and see if it solves the problem.

Thanks, but I'm already doing that, well actually I'm doing this:

if($self->param('r')){
 $config_file = $r->dir_config('CONFIG_FILE');
}

which should be the same, no?

Re: Troubleshooting Apache2 Segfaults

Posted by Robert Landrum <rl...@aol.net>.
Joel Gwynn wrote:
> Interesting.  I just might be doing that:
> $config_file = $self->param('r')->dir_config('CONFIG_FILE');
> 
> In my <Directory> section, I have this:
> 
> PerlSetVar CONFIG_FILE /projects/funnyr_dev/private/config.ini
> 
> And of course I'm not using flock on that file.  Hmmm.

Try changing that up...

my $r = $self->param('r');
if(defined $r) {
   $config_file = $r->dir_config('CONFIG_FILE');
}
else {
   # handle no $r
}

Give that a shot and see if it solves the problem.

Rob

Re: Troubleshooting Apache2 Segfaults

Posted by Robert Landrum <rl...@aol.net>.
Joel Gwynn wrote:
> Here's my backtrace, any ideas?
> 
> #0  0xb7a58743 in modperl_dir_config (my_perl=0x81b6eb0, r=0x823ce98,
> s=0x203a6e6f,
>    key=0x8800c38 "CONFIG_FILE", sv_val=0x0) at modperl_util.c:516
> #1  0xb78dae84 in XS_Apache2__RequestRec_dir_config
> (my_perl=0x81b6eb0, cv=0x82cd074)
>    at RequestUtil.xs:301

I believe the reason it's dumping core is because modperl_dir_config is 
trying to copy the value requested to the sv_val, which is null.

Looks like a bad dir_config call.  Are you doing anything funky, like 
passing in undef, or maybe calling it without an assignment (although 
that shouldn't cause this error)?

Rob


Re: Troubleshooting Apache2 Segfaults

Posted by Joel Gwynn <jo...@gmail.com>.
On 1/22/07, Perrin Harkins <ph...@gmail.com> wrote:
> On 1/21/07, Joel Gwynn <jo...@gmail.com> wrote:
> > I've got a mod_perl application which segfaults on every 10th or so
> > requests.  Here's what I get in my error log:
> >
> > [notice] child pid xxxx exit signal Segmentation fault (11)
> >
> > How would I go about troubleshooting this?
>
> There are instructions for getting a backtrace here:
> http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems
>
> - Perrin
>

Soooo ... I've recompiled mod_perl with MP_DEBUG=1 and I've got some
core dumps.  I'm hoping I don't need to recompile perl because I'm
using debian, and perl and debian are so closely intertwined that that
could be tricky.

Here's my backtrace, any ideas?

#0  0xb7a58743 in modperl_dir_config (my_perl=0x81b6eb0, r=0x823ce98,
s=0x203a6e6f,
    key=0x8800c38 "CONFIG_FILE", sv_val=0x0) at modperl_util.c:516
#1  0xb78dae84 in XS_Apache2__RequestRec_dir_config
(my_perl=0x81b6eb0, cv=0x82cd074)
    at RequestUtil.xs:301
#2  0xb79a3ab9 in Perl_pp_entersub () from /usr/lib/libperl.so.5.8
#3  0xb799bc99 in Perl_runops_standard () from /usr/lib/libperl.so.5.8
#4  0xb793e459 in Perl_call_sv () from /usr/lib/libperl.so.5.8
#5  0xb793e23d in Perl_call_sv () from /usr/lib/libperl.so.5.8
#6  0xb7a5401a in modperl_callback (my_perl=0x81b6eb0,
handler=0x80dae20, p=0x8240e70,
    r=0x8240ea8, s=0x80e2c78, args=0x8aae448) at modperl_callback.c:101
#7  0xb7a54918 in modperl_callback_run_handlers (idx=6, type=4,
r=0x8240ea8, c=0x0,
    s=0x80e2c78, pconf=0x0, plog=0x0, ptemp=0x0, run_mode=MP_HOOK_RUN_FIRST)
    at modperl_callback.c:262
#8  0xb7a54df5 in modperl_callback_per_dir (idx=6, r=0x8240ea8,
run_mode=MP_HOOK_RUN_FIRST)
    at modperl_callback.c:369
#9  0xb7a4cb09 in modperl_response_handler_run (r=0x8240ea8, finish=0)
at mod_perl.c:995
#10 0xb7a4ce3c in modperl_response_handler_cgi (r=0x8240ea8) at mod_perl.c:1090
#11 0x08078375 in ap_run_handler ()
#12 0x08078980 in ap_invoke_handler ()
#13 0x08069c6a in ap_process_request ()
#14 0x0806512d in _start ()
#15 0x08240ea8 in ?? ()
#16 0x00000004 in ?? ()
#17 0x08240ea8 in ?? ()
#18 0xb7a6e6f1 in modperl_process_connection_handler (c=0x8236f58) at
modperl_hooks.c:17
#19 0x080835c5 in ap_run_process_connection ()

Re: Troubleshooting Apache2 Segfaults

Posted by Perrin Harkins <ph...@gmail.com>.
On 1/21/07, Joel Gwynn <jo...@gmail.com> wrote:
> I've got a mod_perl application which segfaults on every 10th or so
> requests.  Here's what I get in my error log:
>
> [notice] child pid xxxx exit signal Segmentation fault (11)
>
> How would I go about troubleshooting this?

There are instructions for getting a backtrace here:
http://perl.apache.org/docs/2.0/user/help/help.html#Reporting_Problems

- Perrin