Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Calls to Apache::Request's param method sometimes end the program and return no data

by cfreak (Chaplain)
on Dec 02, 2004 at 18:08 UTC ( #411893=perlquestion: print w/ replies, xml ) Need Help??
cfreak has asked for the wisdom of the Perl Monks concerning the following question:

I have a large mod_perl program that uses Apache::Request. My site is getting ready to go live and as more and more people are in it, testing, adding data, etc. I've started seeing instances where something is clicked and nothing happens (Firefox is the browser). Other people are reporting this behavior as well.

After testing for two days I finally discovered that this seems to appear when I make a call to $apr->param('someparam');. Warnings just before the call appear in the log correctly but on some requests it does not continue past this point. Instead of getting an error in the logs or to the browser, its as though nothing happened.

My code is too long to post all of it here but here's the basic setup:

# main handler use strict; # this is a sub-class of my module WSC::Common which puts a # database handle and the request object in a common object # (as well as sets up all the other functions etc.) use SWMetal::Init (); # Configuration for this site use SWMetal::Conf (); # all the other needed modules are in the startup.pl sub handler { my $r = shift; my $apr = Apache::Request->new($r); my $conf = SWMetal::Conf->new(); my $common = SWMetal::Init->new($apr,$conf,{admin=>1}); my %admin_scripts = ( # Here theres a hash with referenced functions # that can get called. ); # I call them 'scripts' because to make URLs shorter # I used the path_info function my $script = $apr->path_info(); # some regex stuff here to strip any slashes or other # unwanted stuff from $script if(exists $admin_scripts{$script}) { return $admin_scripts{ $script }->($common); } else { return $admin_scripts{default}->($common); } } # all that works fine .. then in the called function sub foo { my $common = shift; # usually there is some kind of request. my $apr = $common->apr; # common has an AUTOLOAD sub that returns +the key of the hash based on the function name. # Then the problem occurs here, with the first call to param(): my $request = $apr->param('request'); # .... more stuff }

Oh and basically all SWMetal::Init does is, use WSC::Common as its base and define some functions. Common uses several modules as its base and connects to the database. Then it returns a blessed reference that contains the database handle, the conf and the apr passed to it. Calls to SWMetal::Init->new() return $self->SUPER::new().

The problem doesn't happen everytime, if it happens, often clicking the link or button again will get it to go on through. I'm completely stumped.... anyone seen behavior like this before?

UPDATE I found in the main error log that the children of these requests are actually segfaulting :(. I have a backtrace, looks like the segfault occurs in the request table ... not really sure how to fix the problem, hopefully someone on the mod_perl list can help me ...

Comment on Calls to Apache::Request's param method sometimes end the program and return no data
Select or Download Code
Re: Calls to Apache::Request's param method sometimes end the program and return no data
by perrin (Chancellor) on Dec 02, 2004 at 18:44 UTC
    There's nothing wrong with the code you posted here, but it is possible that you have an accidental closure somewhere that causes you to keep an old $apr around and try to use it after the XS side has gone away. The best way to troubleshoot is usually to use the -X flag to httpd, so that you get a single process. This will let you reproduce the problem reliably.

    You may get better help on the mod_perl list. You should provide your OS and versions of apache, mod_perl, perl, and libapreq. There is a reporting script on the mod_perl site that can grab this for you.

    If you are desperate to fix this quickly, I suggest just dropping Apache::Request and using something pure perl and fast, like CGI_Lite or CGI::Simple.

      Thanks for your reply. I will try the -X flag.

      Can you give me an example some code that would cause a closure that you describe?

      I'd love to just switch to a different module. Unfortunatly I use a lot of Apache's methods through Apache::Request since Apache::Request is a sub-class. I'd have to go through my entire program change all that so it probably wouldn't save me a lot of time :(

        This is an example of a closure:

        my $apr; sub handler { my $r = shift; $apr = Apache::Request->new($r); other_sub(); } sub other_sub { my $foo = $apr->some_method(); }
        Basically, anything where a sub refers to a lexical defined outside of the sub.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-07-12 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls