perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fred Moyer <f...@redhotpenguin.com>
Subject Re: [Fwd: Re: Apache::DBI]
Date Mon, 14 Dec 2009 22:44:49 GMT
On Mon, Dec 14, 2009 at 1:22 PM, Adam Prime <adam.prime@utoronto.ca> wrote:
> This thread is 6 months stale, but Jonathan Swartz just replied to the
> RT ticket, and once again brought it to mind.
>
> Can we please do something about this, even if that something is
> re-releasing Apache::DBI 1.06 as 1.08 (as pgollucci said he was going to
> do over a year and a half ago).

First thing we will need is a patch that doesn't fail when applied - [1].

I may be able to clean it up this week and run the test suite against it.

[1]
svn phred@pooky ~/dev/svn/modperl/Apache-DBI/trunk $ svn update
At revision 890520.
phred@pooky ~/dev/svn/modperl/Apache-DBI/trunk $ patch -p0 < p.patch
patching file lib/Apache/DBI.pm
Hunk #1 succeeded at 39 with fuzz 2.
Hunk #2 FAILED at 124.
Hunk #3 FAILED at 136.
Hunk #4 FAILED at 222.
Hunk #5 succeeded at 236 with fuzz 1.
3 out of 5 hunks FAILED -- saving rejects to file lib/Apache/DBI.pm.rej

>
> Thanks,
>
> Adam
>
>
>
> -------- Original Message --------
> Subject: Re: Apache::DBI
> Date: Mon, 27 Jul 2009 00:06:07 -0400
> From: Adam Prime <adam.prime@utoronto.ca>
> To: Fred Moyer <fred@redhotpenguin.com>
> CC: dev@perl.apache.org
> References: <4A65C9A1.70602@utoronto.ca>
> <4A65EC64.4060804@redhotpenguin.com>     <4A65FE8E.1020205@p6m7g8.com>
> <4A6610A1.7020900@utoronto.ca>   <4A6689E0.2030401@utoronto.ca>
> <ad28918e0907220152o6cfe5272r5280d8b19f1f6161@mail.gmail.com>
> <4A6708EE.7030104@utoronto.ca>
>
> Adam Prime wrote:
>> Fred Moyer wrote:
>>> 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:
>>
>> The code in the ticket was just to illustrate the failure.  I ran into
>> this problem because I wanted to preload a large read-only datastructure
>> out of the database prior to the fork to get it completely shared
>> between all the children.  The handle itself is then disconnected and
>> discarded.
>>
>> Adam
>>
>
> The patch attached ads code to bail out of connect() calls called prior
> to the fork by setting a package global during the ChildInit phase,
> along with the other patch which was submitted to the users mailing list.
>
> It works fine for me in extremely limited testing.
>
> Thoughts?
>
> Adam
>
>
> Index: lib/Apache/DBI.pm
> ===================================================================
> --- lib/Apache/DBI.pm   (revision 796605)
> +++ lib/Apache/DBI.pm   (working copy)
> @@ -39,6 +39,9 @@
>                                 #   a negative value de-activates ping,
>                                 #   default = 0
>  my %LastPingTime;               # keeps track of last ping per data_source
> +my $ChildExitHandlerInstalled;  # set to true on installation of
> +                                # PerlChildExitHandler
> +my $InChild;
>
>  # Check to see if we need to reset TaintIn and TaintOut
>  my $TaintInOut = ($DBI::VERSION >= 1.31) ? 1 : 0;
> @@ -121,8 +124,7 @@
>     # unpredictable query results.
>     # See: http://perl.apache.org/docs/2.0/user/porting/compat.html#C__Apache__Server__Starting__and_C__Apache__Server__ReStarting_
>     if (MP2) {
> -        require Apache2::ServerUtil;
> -        if (Apache2::ServerUtil::restart_count() == 1) {
> +        if (!$InChild) {
>             debug(2, "$prefix skipping connection during server startup, read the
docu !!");
>             return $drh->connect(@args);
>         }
> @@ -134,6 +136,23 @@
>         }
>     }
>
> +    # this PerlChildExitHandler is supposed to disconnect all open
> +    # connections to the database
> +    if (!$ChildExitHandlerInstalled) {
> +        $ChildExitHandlerInstalled = 1;
> +        my $s;
> +        if (MP2) {
> +            $s = Apache2::ServerUtil->server;
> +        }
> +        elsif (Apache->can('push_handlers')) {
> +            $s = 'Apache';
> +        }
> +        if ($s) {
> +            debug(2, "$prefix push PerlChildExitHandler");
> +            $s->push_handlers(PerlChildExitHandler => \&childexit);
> +        }
> +    }
> +
>     # this PerlCleanupHandler is supposed to initiate a rollback after the
>     # script has finished if AutoCommit is off.  however, cleanup can only
>     # be determined at end of handle life as begin_work may have been called
> @@ -203,6 +222,7 @@
>     my $prefix = "$$ Apache::DBI            ";
>     debug(2, "$prefix PerlChildInitHandler");
>
> +    $InChild = 1;
>     %Connected = () if MP2;
>
>     if (@ChildConnect) {
> @@ -216,6 +236,22 @@
>     1;
>  }
>
> +# The PerlChildExitHandler disconnects all open connections
> +sub childexit {
> +
> +    my $prefix = "$$ Apache::DBI            ";
> +    debug(2, "$prefix PerlChildExitHandler");
> +
> +    foreach my $dbh (values(%Connected)) {
> +        eval { DBI::db::disconnect($dbh) };
> +        if ($@) {
> +            debug(2, "$prefix DBI::db::disconnect failed - $@");
> +        }
> +    }
> +
> +    1;
> +}
> +
>  # The PerlCleanupHandler is supposed to initiate a rollback after the script
>  # has finished if AutoCommit is off.
>  # Note: the PerlCleanupHandler runs after the response has been sent to
>
>
>
>
>
> ---------------------------------------------------------------------
> 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