Skip Menu | You are currently an anonymous guest. | Login | Return to Main | About rt.cpan.org
 

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.

X Report information
Id: 17446
Status: resolved
Left: 0 min
Priority: 0/0
Queue: Apache-DBI

Owner: Nobody
Requestors: clinton [...] traveljury.com
Cc:
AdminCc:

Severity: Critical
Broken in: 0.9901
Fixed in: (no value)

X Attachments
nocache_during_startup.patch




X History Display mode: Brief headersFull headers
#   Thu Feb 02 15:42:26 2006 guest - Ticket created  
Subject: Not caching connections during startup
[text/plain 984b]
Some of my perl modules connect to the database during startup, and I
have been getting errors when my children try to connect to the
database, because they end up trying to share the $dbh handles from the
parent.

The current code that tries to prevent handle caching (according to the
comments) doesn't do anything except avoid creating connections the
first time the server is started.

if (MP2) {
require Apache2::ServerUtil;
if (Apache2::ServerUtil::restart_count() == 1) {
print STDERR "....."
}
}

However, the server immediately stops and starts again, and all the
handles created in the parent are cached and then shared out to the
children.

And when the server is restarted, the restart_count just keeps going up
- there is now way that I can see of knowing if you are in a restart or
not.

So instead, I've just forced childinit() to be called whether or not you
use connect_on_init and I reset the cache there.

Patch attached

Subject: nocache_during_startup.patch

[text/x-patch 1.2k]

--- Apache/DBI.pm.orig 2006-01-29 01:41:55.000000000 +0100
+++ Apache/DBI.pm 2006-01-29 01:43:34.000000000 +0100
@@ -11,6 +11,8 @@
require mod_perl2;
require Apache2::Module;
require Apache2::ServerUtil;
+ my $s = Apache2::ServerUtil->server;
+ $s->push_handlers(PerlChildInitHandler => \&childinit);
}
elsif (defined $modperl::VERSION && $modperl::VERSION > 1 &&
$modperl::VERSION < 1.99) {
@@ -45,13 +47,7 @@
sub connect_on_init {
# provide a handler which creates all connections during server startup

- if (MP2) {
- if (!@ChildConnect) {
- my $s = Apache2::ServerUtil->server;
- $s->push_handlers(PerlChildInitHandler => \&childinit);
- }
- }
- else {
+ unless (MP2) {
carp "Apache.pm was not loaded\n" and return unless $INC{'Apache.pm'};
if (!@ChildConnect and Apache->can('push_handlers')) {
Apache->push_handlers(PerlChildInitHandler => \&childinit);
@@ -188,6 +184,7 @@
sub childinit {
my $prefix = "$$ Apache::DBI ";
print STDERR "$prefix PerlChildInitHandler \n" if $Apache::DBI::DEBUG > 1;
+ %Connected = ();
if (@ChildConnect) {
for my $aref (@ChildConnect) {
shift @$aref;

#   Sun May 28 06:06:57 2006 PGOLLUCCI - Status changed from 'new' to 'resolved'