Re: Help with a stragegy for diagnosis



On 3/3/07 Malcolm Hoar wrote:

FreeBSD 4.7-RELEASE
Apache 1.3.37
Perl 5.8.4

I have a Perl CGI that has work for years. However,
in the last 24 hours, it has failed two times. It
worked before the first failure. It worked after the
first failure and before the second. It has worked
after the second.

When it failed... it was trying to create (and open
for writing) a simple ASCII file. Fortunately, I did
include code to check for errors on the open(). That
code was executed and did successfully append an
error record to a different log file. Here's the
salient code:

...

Since my error detection and logging is apparently
working, I do have the opportunity to try and
capture/log some other system information if/when
the error arises again. But what data? I can't think
of much that makes sense or would be likely to help.

More information is needed. How are you finding out about the errors?
How comfortable are you with Perl debugging?

As a start, if your WebError subroutine doesn't already do this, try
using CGI::Carp to get more verbose and safer errors and warnings. If
it's OK to expose the errors to users,

use CGI::Carp qw/fatalsToBrowser/;

Otherwise put a carp log file somewhere,

use CGI::Carp qw/carpout/;
open (LOG, ">>var/tmp/mycgi-log")
or die "Can't append to mycgi-log: $1\n";
carpout(*LOG);

[examples from the Camel, 3rd ed., paperback, page 879]

A strategy would be to write tests for the script until you get the same
error, fix the script so those tests pass, then write more tests and
repeat until you can't get that error.

If possible, take your script out of the CGI execution environment, set
it up run in a local shell, and then write tests. If you leave it in
place, you could write a Perl script with the CPAN LWP modules to create
a user agent to send automated calls to your CGI. But remember that your
tests should be failing a lot at first, so use some caution if the CGI
is on someone else's server...

With CGIs I would start with the script's input, including config info.
Test for correct and incorrect user input, speed and sequence of input,
repetition of input, and so on.

Here are some other lines to explore:

* Are you checking for errors when closing files? Maybe something
happened just before the error you're seeing.

* How are these files used by this or any other script once they're
created?

* Disk near full?

$file = $txdir . $sequence;
* Where do the components of the filename come from? Are they
sanity-checked? Does the error message have the expected path for the
file? Could the name have already been in use?

* What permissions would the file be assigned when things work
correctly?

* Does your script or any other modify the directory holding these
files? How many files are in the directory? Does any process clear out
obsolete files?

* Are you logging only errors, or do you also have a way to trace
patterns in normal ops?

* Could you or someone else have been doing maintenance on the server
when the errors occurred?

* Perl version 5.8.4 didn't stay current very long -- you might want to
check for clues in the version history changes, or just upgrade to 5.8.6
or 5.8.8 if that's under your control. Could you locate the script on a
different server and test it there?

* Speaking of versions, the usage
&WebError (...)
suggests Perl 4 legacy code (or maybe a Perl 4 legacy coder -- greetings
comrade!); there might be some other archaism that's causing problems.

* Could the users getting the errors have done something unexpected with
their Web browser Reload or Back commands, or with bookmarks set for
script-generated "pages" from previous visits to your site?

* Were the two errors experienced by the same user?

Good luck!






- Bruce

__bruce__van_allen__santa_cruz__ca__
.



Relevant Pages

  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... from the documentation provided with Perl. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ...
    (comp.lang.perl.misc)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... This message is one of several periodic postings to comp.lang.perl.misc ... from the documentation provided with Perl. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ...
    (comp.lang.perl.misc)
  • Re: Advice about cgi programming
    ... experience with other scripting languages. ... This might not be the most appropriate group, but since Perl is ... input string to this script in the background and return the result. ... Perl is an excellent choice for writing CGI programs. ...
    (comp.lang.perl.misc)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... comes with the standard Perl distribution. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ... The similarity between CGI response headers (defined in the CGI ...
    (comp.lang.perl.misc)
  • FAQ 9.1 What is the correct form of response from a CGI script?
    ... comes with the standard Perl distribution. ... What is the correct form of response from a CGI script? ... The Common Gateway Interface (CGI) specifies a software interface ... The similarity between CGI response headers (defined in the CGI ...
    (comp.lang.perl.misc)