[Rt-commit] rt branch, 3.8/db-handle-disconnected, created. rt-3.8.17-5-g274acaa

Thomas Sibley trs at bestpractical.com
Mon Jun 24 17:59:23 EDT 2013


The branch, 3.8/db-handle-disconnected has been created
        at  274acaa2017bc1178e462d40a6dddc6b894cd069 (commit)

- Log -----------------------------------------------------------------
commit 943acb6ce8f034d7fdae26057bf309f4c6d352a4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Mar 29 13:22:11 2013 +0400

    override _Handle in RT::SearchBuilder
    
    Like in RT::Record - just return $RT::Handle.
    
    This avoids storing $RT::Handle in $sb->{'DBIxHandle'},
    so it is never serialized in $session{'tickets'}. Such
    serialization may lead to disconnection of active handle.
    It happens when $DBIx::SearchBuilder::Handle::PrevHandle
    is set to active handle and $session{'tickets'} gets
    destroyed. It's hard to get triggered in a test.
    
    (cherry picked from commit a20251c5e8f6f59d9007df0902d60b6f949dcda4)
    
    Conflicts:
    	lib/RT/SearchBuilder.pm

diff --git a/lib/RT/SearchBuilder.pm b/lib/RT/SearchBuilder.pm
index 8eeabab..c10908e 100755
--- a/lib/RT/SearchBuilder.pm
+++ b/lib/RT/SearchBuilder.pm
@@ -85,6 +85,8 @@ sub _Init  {
     $self->SUPER::_Init( 'Handle' => $RT::Handle);
 }
 
+sub _Handle { return $RT::Handle }
+
 sub OrderByCols {
     my $self = shift;
     my @sort;

commit 205d55f697c45ab53fbd3a87f8bb94029332b2ab
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Apr 28 17:21:05 2013 +0400

    we were not disconnecting handles on destroy
    
    DisconnectHandleOnDestroy is argument in Connect method,
    not in BuildDSN.
    
    So we were not disconnecting dbh explicitly when RT::Handle is
    destroyed. They are still being disconnected later when dbh goes
    out of scope.
    
    We fix this as this is waht we expect to happen.
    
    (cherry picked from commit 7175272b38dacc18b042930d5722686e63e17af7)
    
    Conflicts:
    	lib/RT/Handle.pm

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e9ee4ab..f6f9b8a 100755
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -112,6 +112,7 @@ sub Connect {
     $self->SUPER::Connect(
         User => RT->Config->Get('DatabaseUser'),
         Password => RT->Config->Get('DatabasePassword'),
+        DisconnectHandleOnDestroy => 1,
     );
 
     if ( $db_type eq 'mysql' ) {
@@ -159,7 +160,6 @@ sub BuildDSN {
         Port       => $db_port,
         Driver     => $db_type,
         RequireSSL => RT->Config->Get('DatabaseRequireSSL'),
-        DisconnectHandleOnDestroy => 1,
     );
     if ( $db_type eq 'Oracle' && $db_host ) {
         $args{'SID'} = delete $args{'Database'};

commit 4ec96da085c01ad3d8ef9b56db003ebb2fccb7e7
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Nov 9 02:35:34 2011 -0500

    Restore database disconnection state after successful safe_run_child
    
    RT::Util's safe_run_child sets its database handles to not disconnect
    themselves if they are destroyed, before calling the provided function
    which may fork and exec.  It explicitly re-enables those bits prior to
    die'ing if the exec fails, to ensure that the database handle is torn
    down correctly during the global destruction that would shortly ensue.
    
    However, it fails to re-instate those bits after a _successful_ call.
    This leaves the main database handle in a state where it does not tear
    down the connection during global destruction.
    
    This is particularly destructive in the case where:
      (a) RT uses PostgreSQL as its backend database
      (b) The database connection to PostgreSQL uses SSL, as is the default
          if the server supports it
      (c) The RT server is embedded into the Apache server using mod_perl
      (c) Apache has also loaded the SSL libraries for HTTPS support
    
    This causes libcrypto.so to be used in two places in the Apache process,
    by both Perl's binary PostgreSQL driver as well as core Apache's; they
    thus share some internal state.  The lack of orderly teardown of the
    SSL-enabled database connection causes corruption in the SSL engine's
    internal state during the Apache shutdown process, which could lead to
    segmentation faults in Apache.
    
    Resolve this by explicitly re-instating the disconnect-on-destroy flags
    after a successful safe_run_child.
    
    (cherry picked from commit e96831cf8f457b1601dc778cc336d43105f7a38b)

diff --git a/lib/RT/Util.pm b/lib/RT/Util.pm
index f6798fc..0a19eeb 100644
--- a/lib/RT/Util.pm
+++ b/lib/RT/Util.pm
@@ -90,6 +90,8 @@ sub safe_run_child (&) {
         #TODO we need to localize this
         die 'System Error: ' . $err;
     };
+    $dbh->{'InactiveDestroy'} = 0 if $dbh;
+    $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
     return $want? (@res) : $res[0];
 }
 

commit 274acaa2017bc1178e462d40a6dddc6b894cd069
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Apr 28 17:33:44 2013 +0400

    save and restore OLD values in safe_run_child
    
    We expected DiconnectHandleOnDestroy to be true,
    but it was not, see 7175272b38dacc18b042930d5722686e63e17af7.
    Save old values and restore them to avoid assumptions.
    
    Restoring to hard coded true value revealed
    a20251c5e8f6f59d9007df0902d60b6f949dcda4.
    
    (cherry picked from commit cd49cafab29e9f1b84783996d9c3306da2684a1a)
    
    Conflicts:
    	lib/RT/Util.pm

diff --git a/lib/RT/Util.pm b/lib/RT/Util.pm
index 0a19eeb..7159a14 100644
--- a/lib/RT/Util.pm
+++ b/lib/RT/Util.pm
@@ -64,8 +64,11 @@ sub safe_run_child (&) {
     # values. Instead we set values, eval code, check pid
     # on failure and reset values only in our original
     # process
+    my ($oldv_dbh, $oldv_rth);
     my $dbh = $RT::Handle->dbh;
+    $oldv_dbh = $dbh->{'InactiveDestroy'} if $dbh;
     $dbh->{'InactiveDestroy'} = 1 if $dbh;
+    $oldv_rth = $RT::Handle->{'DisconnectHandleOnDestroy'};
     $RT::Handle->{'DisconnectHandleOnDestroy'} = 0;
 
     my @res;
@@ -83,15 +86,15 @@ sub safe_run_child (&) {
         my $err = $@;
         if ( $our_pid == $$ ) {
             $RT::Logger->error( $err );
-            $dbh->{'InactiveDestroy'} = 0 if $dbh;
-            $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
+            $dbh->{'InactiveDestroy'} = $oldv_dbh if $dbh;
+            $RT::Handle->{'DisconnectHandleOnDestroy'} = $oldv_rth;
         }
         $err =~ s/^Stack:.*$//ms;
         #TODO we need to localize this
         die 'System Error: ' . $err;
     };
-    $dbh->{'InactiveDestroy'} = 0 if $dbh;
-    $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
+    $dbh->{'InactiveDestroy'} = $oldv_dbh if $dbh;
+    $RT::Handle->{'DisconnectHandleOnDestroy'} = $oldv_rth;
     return $want? (@res) : $res[0];
 }
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list