Class::DBI::Loader w/mod_perl interaction bug (solved)

Toby Corkindale tjc at wintrmute.net
Thu Jan 5 18:19:38 GMT 2006


OK, after some discussion on #catalyst, the problem with Class::DBI::Loader
causing extreme database weirdness to occur is solved.

cDBI::Loader makes an initial connection to the database, before Apache forks
off. It's meant to just look up the tables and then disconnect.. However it
appears that both the mysql and postgres Class::DBI::{Pg,Mysql} modules manage
to hang onto the database handle and prevent it from being disconnected.

Thus, after Apache forks off the child handlers, they are still using the old
connection, and sharing a single socket to the database - with predictably
chaotic results.

The workaround is to forcibly disconnect the DB immediately after the
Loader->new() call, which will cause the children to have to reconnect, thus
getting their own unique DB handles.

Another workaround is to called Loader post-fork, in a child init handler, but
then you don't have access to the created virtual packages until then either,
which may be a hassle for you, or not, depending on when you start using them.


Cheers,
Toby
(plus thanks to mst+andyg)
 

-- 
Turning and turning in the widening gyre/The falcon cannot hear the falconer;
Things fall apart, the centre cannot hold/Mere anarchy is loosed upon the world
(gpg --keyserver www.co.uk.pgp.net --recv-key B1CCF88E)


More information about the london.pm mailing list