Greetings,
First things first: I'm running mod_perl 1.29 with Apache 1.3 on FreeBSD 5.1.
I have been developing a mod_perl application (showing a "We're processing your request" page while running a lengthy database query) that requires forking. I've read through the mod_perl forking docs and I think I've structured my code pretty much by-the-book:
$SIG{CHLD} = 'IGNORE'; defined (my $childpid = fork) or carp "Could not fork";
if ($childpid) { # ensure that the chile can still use the handle # after the parent's copy has gone out of scope $DBH->{InactiveDestroy} = 1;
# show the "We're processing your request" page } else { open STDIN, "</dev/null"; open STDOUT, ">/dev/null"; eval { # call the subroutine containing the long-running query }; if ($@) { carp $@; }
CORE::exit(0); }
The problem is that I get varying results when I run an automated test script against this code (while in single-process mode, of course). Sometimes I get the following error:
server sent data ("D" message) without prior row description ("T" message)
Other times I get various weird DBD::Pg warnings or errors that should not be happening. Occasionally, things just hang for a few minutes before a "500 read timeout" is generated. There are still other times when everything runs absolutely fine. In addition, each time one of these unfortunate problems occur I'm left with an idle child process that just sits around until I kill it.
Because most of the errors I get are database-flavored, I'm thinking that the issue has to do with sharing the database handle across the fork. The DBI documentation says that setting InactiveDestroy on the handle is the way to do that. Indeed, when I test my code as a regular cgi script without mod_perl I don't have these problems, so running under mod_perl seems to be a contributing factor as well.
Finally, one item that might be related is the use of CORE::exit(0). The mod_perl "Performance Tuning" guide (and most other mod_perl forking resources as well) advocate using this function. However the mod_perl "Porting" guide says that CORE::exit should not be used (because a "proper exit" does not happen) and that Apache::exit(Apache::Constraints::DONE) or $r->child_terminate should be used instead. Could CORE::exit's improper exiting be messing up the database handles? In general, which of these three child terminating routines should I be using?
Thank you for any help you can provide.
--Matt
-- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html