Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

mason/mod_perl/apache debugging and testing

by jimbus (Friar)
on Jul 26, 2006 at 19:20 UTC ( [id://563871]=perlquestion: print w/replies, xml ) Need Help??

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

OK,

This is the something I posted in fair detail to the mason users group, but I didn't get much response... so let's try this from a more abstract perspective.

If I have a perl module that test rock solid from the command line at accessing and returning its data, but starts failing and failing more often the longer its in service, when running through Apache/mod_perl/mason... how do I go about debugging this?

So far I'm using Data Dumper on the PM and CGI sides and using various print statements in the PM and I haven't made any headway. I think that something may have been caching even though I restart apache each time I make a change to the PM, because I was getting out of date data when I dumped the object. I do an opendir as the basis to getting the data and put an "or die 'dead'" on the end. It didn't fire on failure at first, but once I got past the caching thing, it started showing up when the system failed.

Any ideas or methods would be greatly appreciated.

Also, I'm pretty thourogh about testing the perl modules with test scripts, testing for results over many iterations, but it is apparent that I need similar testing of the pm/cgi/apache/mod_perl/mason components working as a whole. Can anyone point me at some documents discussing best or even good practices for this?

Thanks,


--Jimbus aka Jim Babcock
Wireless Data Engineer and Geek Wannabe
jim-dot-babcock-at-usa-dot-com
  • Comment on mason/mod_perl/apache debugging and testing

Replies are listed 'Best First'.
Re: mason/mod_perl/apache debugging and testing
by duckyd (Hermit) on Jul 26, 2006 at 20:31 UTC
    Instead of "or die 'dead'", what do you get if you die "failed : $!\n"?

    Beyond that, there's a few things to check. I believe that you can see if Mason caching is the issue by clearing out the mason cache/ directory. You can see if mason's "compilation" is to blame by clearing out the obj/ directory.

    Do you have globals around that might cause an issue in a mod_perl environment?

    You can always write a test script to hit your webserver and trigger the error. Making it easier to reproduce may help you find the cause faster.

Re: mason/mod_perl/apache debugging and testing
by cowboy (Friar) on Jul 26, 2006 at 22:48 UTC

    The first thing to do I would think is to run apache in single server mode. (I think httpd -x).

    My first thought would be global variables sticking around due to the persistant perl process.

    After that, it shouldn't be too hard if you keep it simple. Try running your test suite under mason. Most of the scripts should be trivial to turn into mason components.

    Can your tests run in a loop/persistant environment? Can 2 processes run in a loop together?

Re: mason/mod_perl/apache debugging and testing
by fmerges (Chaplain) on Jul 27, 2006 at 08:48 UTC

    Hi,

    One thing, first it would be very useful to know which versions you're running, Mason, Apache, mod_perl etc... because knowing this we can get closer to what could be happen...

    You don't show any code line to see how you're calling this "rock solid stuff". So that I can only tell you, be sure to use lexical scope inside your Mason components.

    Do you have wrote this module? with 'strict' and 'warnings'. Putting special vars with 'local', using lexical scope via 'my'?

    Take also a look at Mason Book Online and Practical mod_perl.

    Regards,

    fmerges at irc.freenode.net

      This is from the original email...

      Architecturally, Its Apache 2.2, Mason 1.33, mod_perl 2.0.2. Like all good coders should I put the non-display code in reasonably OO PMs and 'use' it in the mason template. I set up test scripts for each sub and test they as best I can. In fact, once I started having issues with this object, I set it up to run a million times and had no failures from the script on several attempts.

      The object is pretty simple. It takes a path as an argument and returns either a list of directories or file names as urls. Departments use ftp to upload documents and reports to the directory structure and then this web app allows others to read them. The base URL is hardcoded in the PM and there are regexes to avoid spoofing, it seems pretty rock solid. the issue is that the longer the server is up, the more often it falsely returns an object with no URLs. Dumping the document, I see that some of the fields are not defaults, but prints at various points in the method don't print. This is where I noticed that it appears to be caching... I noticed some things in the dumped object are from earlier iterations of the object. If anyone has a good idea why this is happening or suggestions on how to debug it, I would sure appreciate this. The code is below JimB

      #! /usr/local/perl package Dir; use strict; Dir.pm: sub get_list { my $self = (); shift; $self->{base} = "/usr/local/www/uploads/SS7"; $self->{URI} = shift; $self->{path} = ""; $self->{title} = ""; $self->{leaf} = "false"; $self->{names} = (); $self->{urls} = (); bless($self); $self->{title} = $self->{URI}; $self->{path} = $self->{base} . $self->{URI} . "/"; opendir DH, $self->{path}; my @save_files; while (my $line = readdir(DH)) { my $path = $self->{path} . $line; if ((-d $path) && ($line !~ /\.$/)) { $self->{names}{$line} = $line; $self->{names}{$line} =~ tr/_/ /d; $self->{urls}{$line} = $line; } else { push (@save_files, $line); } } my $count = scalar (keys %{$self->{names}}); if ($count == 0) { foreach my $line (@save_files) { next if (-d $line); $self->{names}{$line} = $line; $self->{names}{$line} =~ tr/_/ /d; $self->{names}{$line} =~ tr/.xls//d; $self->{urls}{$line} = $line; } $self->{leaf} = "true"; } return($self); } 1;

      Reports.cgi:

      % if (defined $rep->{title}) { % $rep->{title} =~ tr/_/ /; % $rep->{title} =~ tr/\// /; <h3><& SELF:title &><font size="-1"> <% $rep->{title} %></font></h3> % } else { <h3><& SELF:title &> </h3> % } <ul class="menulist"> % if ($rep->{leaf} eq "true") { % my %tmp_names = (); % my %tmp_urls = (); % foreach $iter (sort {$b cmp $a} keys %{$rep->{urls}}) { % if ($rep->{names}->{$iter} =~/(\d\d)(\d\d)(\d\d)/) { % $tmp_names{"$3$1$2"} = $mos[$1] . " $2, 20$3"; % $tmp_urls{"$3$1$2"} = $rep->{urls}->{$iter}; % } % } foreach $iter (sort {$b <=> $a} keys %tmp_names) { <li> <a href="/files/SS7/<% $rep->{URI} %>/<% $tmp_urls{$iter} %>"> < +% $tmp_names{$iter} %></a> % } } else { % foreach $iter (sort {$b cmp $a} keys %{$rep->{urls}}) { <li> <a href="<% $r->uri %>?rep=<% $rep->{URI} . "/" . $rep->{urls}-> +{$iter} %>&app=SS7/Reports"> <% $rep->{names}->{$iter} %></a> % } % } </ul> </div> <%method title> SS7: </%method> <%once> use Apps::SS7::Dir; use Data::Dumper; </%once> <%init> my @mos = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept"," +Oct","Nov","Dec"); my $item; my $iter; my $rep = Dir->get_list($ARGS{rep}); </%init>

      Here is the httpd.conf section:

      DocumentRoot "/usr/local/www/docs" # # Each directory to which Apache has access can be configured with res +pect # to which services and features are allowed and/or disabled in that # directory (and its subdirectories). # # First, we configure the "default" to be a very restrictive set of # features. # <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. # # # This should be changed to whatever you set DocumentRoot to. # PerlRequire /usr/local/www/lib/uses.pl PerlSwitches -wT PerlSetVar MasonCompRoot /usr/local/www/docs PerlAddVar MasonDataDir /usr/local/httpd/mason PerlAddVar MasonAllowGlobals $AuthDBH PerlAddVar MasonAllowGlobals $RepDBH PerlAddVar MasonAllowGlobals $SysDBH PerlAddVar MasonAllowGlobals $User PerlModule HTML::Mason::ApacheHandler PerlModule Apache::DBI PerlModule Apache2::Cookie PerlModule CGI PerlModule Apache2::Const <FilesMatch "(\.html|\.css)$"> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler </FilesMatch> # <FilesMatch "(\.cgi)$"> # SetHandler perl-script # PerlHandler "sub { return Apache2::Const::NOT_FOUND }" # </FilesMatch> <Directory "/usr/local/www/docs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI M +ultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options A +ll" # doesn't give it to you. # # The Options directive is both complicated and important. Please + see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htacces +s files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory>

      --Jimbus aka Jim Babcock
      Wireless Data Engineer and Geek Wannabe
      jim-dot-babcock-at-usa-dot-com

        You should check to see whether opendir is sucessful. If it fails, some of your values, such as

        $self->{leaf}
        will be changed to non-defaults.

        Beyond that, you could be having any number of problems with your mason code. Don't be afraid to use <%perl> blocks and $m->print, or to move more code into your <%init> block to make things easier to read. Your reporting component makes my head hurt just looking at it.

Re: mason/mod_perl/apache debugging and testing
by Miguel (Friar) on Jul 26, 2006 at 23:10 UTC
    "So far I'm using Data Dumper on the PM and CGI sides and using various print statements in the PM"
    I'm not sure here, but 'print'ing from inside a perl module might be a problem with mod_perl.

      Hi,

      Why?

      Regards,

      fmerges at irc.freenode.net

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-23 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found