[Dbix-class] Patch and test for DBIx::Class storage->connected() bug
luke saunders
luke.saunders at gmail.com
Tue Aug 7 12:02:37 GMT 2007
There is a bug in method connected of DBIx::Class::Storage::DBI: it
doesn't check that $dbh is still valid after it has called
$self->_verify_pid. _verify_pid() will invalidate $dbh if the connection
has been created in a different process (the parent).
Here is a patch with a potential fix and a test case for this problem.
Index: t/50fork.t
===================================================================
--- t/50fork.t (revision 3641)
+++ t/50fork.t (working copy)
@@ -18,7 +18,7 @@
$num_children = 10;
}
-plan tests => $num_children + 5;
+plan tests => $num_children + 6;
use lib qw(t/lib);
@@ -45,6 +45,23 @@
};
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) {
Index: lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- lib/DBIx/Class/Storage/DBI.pm (revision 3641)
+++ lib/DBIx/Class/Storage/DBI.pm (working copy)
@@ -665,6 +665,7 @@
}
else {
$self->_verify_pid;
+ return 0 if !$self->_dbh;
}
return ($dbh->FETCH('Active') && $dbh->ping);
}
More information about the DBIx-Class
mailing list