[Rt-commit] rt branch, 4.0/disconnect-on-destroy, created. rt-4.0.11rc1-8-gcd49caf

Ruslan Zakirov ruz at bestpractical.com
Sun Apr 28 09:39:54 EDT 2013


The branch, 4.0/disconnect-on-destroy has been created
        at  cd49cafab29e9f1b84783996d9c3306da2684a1a (commit)

- Log -----------------------------------------------------------------
commit 7175272b38dacc18b042930d5722686e63e17af7
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.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 0a1d61e..31dc403 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -114,6 +114,7 @@ sub Connect {
     $self->SUPER::Connect(
         User => RT->Config->Get('DatabaseUser'),
         Password => RT->Config->Get('DatabasePassword'),
+        DisconnectHandleOnDestroy => 1,
         %args,
     );
 
@@ -161,7 +162,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 cd49cafab29e9f1b84783996d9c3306da2684a1a
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.

diff --git a/lib/RT/Util.pm b/lib/RT/Util.pm
index 38c3c20..ee63e3a 100644
--- a/lib/RT/Util.pm
+++ b/lib/RT/Util.pm
@@ -65,8 +65,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 ($reader, $writer);
@@ -90,8 +93,8 @@ sub safe_run_child (&) {
         my $err = $@;
         $err =~ s/^Stack:.*$//ms;
         if ( $our_pid == $$ ) {
-            $dbh->{'InactiveDestroy'} = 0 if $dbh;
-            $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
+            $dbh->{'InactiveDestroy'} = $oldv_dbh if $dbh;
+            $RT::Handle->{'DisconnectHandleOnDestroy'} = $oldv_rth;
             die "System Error: $err";
         } else {
             print $writer "System Error: $err";
@@ -104,8 +107,8 @@ sub safe_run_child (&) {
     my ($response) = $reader->getline;
     warn $response if $response;
 
-    $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