perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fred Moyer <f...@redhotpenguin.com>
Subject Re: Apache::DBI
Date Wed, 22 Jul 2009 08:52:14 GMT
On Tue, Jul 21, 2009 at 8:39 PM, Adam Prime<adam.prime@utoronto.ca> wrote:
> Adam Prime wrote:
>> What I wanted to do was fix this issue:
>>
>> http://rt.cpan.org/Public/Bug/Display.html?id=36346

I was just looking over your original code where you connect() in
startup.pl.  Won't that cause issues since the database handle will be
forked also?  Here's what I have in my startup.pl:

use Apache::DBI             ();
use Some::Database::Modules ();
use DBI         ();
use DBD::Pg     ();
DBI->install_driver('Pg');

$Apache::DBI::DEBUG = $config->sl_db_debug;
my $db_connect_params = SL::Model->connect_params;
Apache::DBI->connect_on_init( @{$db_connect_params} );
Apache::DBI->setPingTimeOut( $db_connect_params->[0],
    $config->sl_db_ping_timeout );

# delete this line and I will beat you with a stick
# we need to disconnect before the fork
SL::Model->connect->disconnect;
$DBI::connect_via = 'Apache::DBI::connect';

print STDOUT "Startup.pl finished...\n";


I had to leave myself a threatening message in my code as a warning
not to have an open database handle in startup.pl.  I'd been told by
Perrin and others why it was necessary, but it wasn't until I screwed
up my own code and experienced the full wrath of a forked httpd child
with a shared db handle cause database transactions to fail at random.

I


>>
>> either by checking the various server starting variables for each of the
>> apis, or simply throwing an eval around the push_handler.
>
> I've been looking into this bug a bit tonight, and it seems to me that
> the problem is maybe with restart_count.
>
> This code:
>
> if (Apache2::ServerUtil::restart_count() == 1) {
>    debug(2, "$prefix skipping connection during server startup, read
> the docu !!");
>    return $drh->connect(@args);
> }
>
> appears earlier in the connect function, and based on the comments, it
> would appear that any connection to the database that happens during
> startup (which to me should mean any time before the end of the
> ChildInitPhase) should not be cached. The problem is PostConfig is run
> twice on startup, once with restart_count == 1, and once with
> restart_count == 2.  So the second time through, it gets past that if
> statement, and blows up when it hits the code that tries to push_handler().
>
> The documentation here is also no longer true:
>
> http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_restart_count_
>
> If I put that code into my startup.pl, i get:
>
> cnt: 1
> cnt: 2
> cnt: 3
> cnt: 4
> cnt: 5
> cnt: 6
> cnt: 7
>
> I'm going to fool around with things a bit more.
>
> Adam
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
> For additional commands, e-mail: dev-help@perl.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message