[Rt-commit] rt branch, 4.0/dbh-disconnect-after-safe-run-child, updated. rt-4.0.3-47-g224781e

Alex Vandiver alexmv at bestpractical.com
Tue Dec 13 16:48:09 EST 2011


The branch, 4.0/dbh-disconnect-after-safe-run-child has been updated
       via  224781e7720e0569801fc0ddb211f57b3671e7c3 (commit)
       via  3f09bda0711095cd401624059cafbd7a6fd491c9 (commit)
       via  35c50f28caeb044ebe04a53d409cecefbf6a847b (commit)
       via  a4130fb46eb8d313a07ecf53b41e63f2fe01dbef (commit)
      from  72ddb36099be24f17fb7ee27a0666786729ed6ac (commit)

Summary of changes:
 lib/RT/Util.pm              |   15 ++++++++++-----
 t/api/safe-run-child-util.t |   28 +++++++++++++++++++++++++---
 2 files changed, 35 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit a4130fb46eb8d313a07ecf53b41e63f2fe01dbef
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 13 16:30:49 2011 -0500

    Ensure that we generate the warning we expect if the child dies

diff --git a/t/api/safe-run-child-util.t b/t/api/safe-run-child-util.t
index e9674cf..bfce3fa 100644
--- a/t/api/safe-run-child-util.t
+++ b/t/api/safe-run-child-util.t
@@ -3,7 +3,8 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 23;
+use RT::Test tests => 24;
+use Test::Warn;
 
 use RT::Util qw(safe_run_child);
 
@@ -61,20 +62,22 @@ is_handle_ok();
 
 # fork+child dies
 {
-    my $res = safe_run_child {
-        if (fork) { wait; return 'parent' }
-
-        open my $fh, '>', RT::Test->temp_directory .'/tttt';
-        print $fh "child";
-        close $fh;
-
-        die 'child';
-    };
-    is $res, 'parent', "correct return value";
-    is( RT::Test->file_content([RT::Test->temp_directory, 'tttt'], unlink => 1 ),
-        'child',
-        'correct file content',
-    );
+    warning_like {
+        my $res = safe_run_child {
+            if (fork) { wait; return 'parent' }
+
+            open my $fh, '>', RT::Test->temp_directory .'/tttt';
+            print $fh "child";
+            close $fh;
+
+            die 'child';
+        };
+        is $res, 'parent', "correct return value";
+        is( RT::Test->file_content([RT::Test->temp_directory, 'tttt'], unlink => 1 ),
+            'child',
+            'correct file content',
+        );
+    } qr/System Error: child/;
     is_handle_ok();
 }
 

commit 35c50f28caeb044ebe04a53d409cecefbf6a847b
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 13 16:31:36 2011 -0500

    We expect a $@ re-thrown with System Error

diff --git a/t/api/safe-run-child-util.t b/t/api/safe-run-child-util.t
index bfce3fa..63b919d 100644
--- a/t/api/safe-run-child-util.t
+++ b/t/api/safe-run-child-util.t
@@ -85,7 +85,7 @@ is_handle_ok();
 {
     my $res = eval { safe_run_child { die 'parent'; } };
     is $res, undef, "correct return value";
-    like $@, qr'parent', "correct return value";
+    like $@, qr'System Error: parent', "correct error message value";
     is_handle_ok();
 }
 

commit 3f09bda0711095cd401624059cafbd7a6fd491c9
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 13 16:32:15 2011 -0500

    Add a test for the child exiting cleanly

diff --git a/t/api/safe-run-child-util.t b/t/api/safe-run-child-util.t
index 63b919d..f5d78b3 100644
--- a/t/api/safe-run-child-util.t
+++ b/t/api/safe-run-child-util.t
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 24;
+use RT::Test tests => 27;
 use Test::Warn;
 
 use RT::Util qw(safe_run_child);
@@ -81,6 +81,25 @@ is_handle_ok();
     is_handle_ok();
 }
 
+# fork+child exits
+{
+    my $res = safe_run_child {
+        if (fork) { wait; return 'parent' }
+
+        open my $fh, '>', RT::Test->temp_directory .'/tttt';
+        print $fh "child";
+        close $fh;
+
+        exit 0;
+    };
+    is $res, 'parent', "correct return value";
+    is( RT::Test->file_content([RT::Test->temp_directory, 'tttt'], unlink => 1 ),
+        'child',
+        'correct file content',
+    );
+    is_handle_ok();
+}
+
 # parent dies
 {
     my $res = eval { safe_run_child { die 'parent'; } };

commit 224781e7720e0569801fc0ddb211f57b3671e7c3
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Dec 13 16:32:41 2011 -0500

    Safely report fatal errors in children of safe_run_child in the parent
    
    In the event of a fork, the RT logger object may have shared sockets
    open, and as such may not be usable.  In order to ensure that the fatal
    error in the child is not silently discarded, write it to a pipe which
    is left open in the parent.  The contents of this pipe are read in the
    parent, and re-thrown as a warning.

diff --git a/lib/RT/Util.pm b/lib/RT/Util.pm
index b66b607..32932a0 100644
--- a/lib/RT/Util.pm
+++ b/lib/RT/Util.pm
@@ -69,6 +69,9 @@ sub safe_run_child (&) {
     $dbh->{'InactiveDestroy'} = 1 if $dbh;
     $RT::Handle->{'DisconnectHandleOnDestroy'} = 0;
 
+    my ($reader, $writer);
+    pipe( $reader, $writer );
+
     my @res;
     my $want = wantarray;
     eval {
@@ -85,19 +88,21 @@ sub safe_run_child (&) {
         1;
     } or do {
         my $err = $@;
-        $RT::Logger->error( $err ) if $our_pid == $$;
         $err =~ s/^Stack:.*$//ms;
         if ( $our_pid == $$ ) {
             $dbh->{'InactiveDestroy'} = 0 if $dbh;
             $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
-            #TODO we need to localize this
-            die 'System Error: ' . $err;
+            die "System Error: $err";
         } else {
-            local $SIG{__WARN__};
-            warn 'System Error: ' . $err;
+            print $writer "System Error: $err";
             exit 1;
         }
     };
+
+    close($writer);
+    my ($response) = <$reader>;
+    warn $response if $response;
+
     $dbh->{'InactiveDestroy'} = 0 if $dbh;
     $RT::Handle->{'DisconnectHandleOnDestroy'} = 1;
     return $want? (@res) : $res[0];

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


More information about the Rt-commit mailing list