From: Luke Saunders Date: Tue, 7 Aug 2007 14:11:18 +0000 (+0000) Subject: fixed storage->connected fork bug X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=649bfb8c11af342bcf7880ba52a7060a69c54068;hp=70f3927877ba6b7aac2565bc1933daaf82361308;p=dbsrgits%2FDBIx-Class-Historic.git fixed storage->connected fork bug --- diff --git a/Changes b/Changes index d04a54d..4fbcedd 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class - + - fixed storage->connected fork bug + (test and fix from Radu Greab) - refactor Statistics to create debugging filehandle to fix bug with closed STDERR, update docs and modify Versioned to use Statistics (original fix from diz) diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 996f9e0..eae06c2 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -668,6 +668,7 @@ sub connected { } else { $self->_verify_pid; + return 0 if !$self->_dbh; } return ($dbh->FETCH('Active') && $dbh->ping); } diff --git a/t/50fork.t b/t/50fork.t index d42c0f4..8379547 100644 --- a/t/50fork.t +++ b/t/50fork.t @@ -18,7 +18,7 @@ if($num_children !~ /^[0-9]+$/ || $num_children < 10) { $num_children = 10; } -plan tests => $num_children + 5; +plan tests => $num_children + 6; use lib qw(t/lib); @@ -45,6 +45,23 @@ eval { }; ok(!$@) or diag "Creation eval failed: $@"; +{ + my $pid = fork; + if(!defined $pid) { + die "fork failed: $!"; + } + + if (!$pid) { + exit $schema->storage->connected ? 1 : 0; + } + + if (waitpid($pid, 0) == $pid) { + my $ex = $? >> 8; + ok($ex == 0, "storage->connected() returns false in child"); + exit $ex if $ex; # skip remaining tests + } +} + my @pids; while(@pids < $num_children) {