[Dbix-class] [Resending in plain text format] [rt.cpan.org #35942] Connections remain open even when out of scope

Matt S Trout dbix-class at trout.me.uk
Sun Jul 20 01:48:35 BST 2008


On Fri, Jul 04, 2008 at 04:32:24PM +0530, jothi libitha wrote:
> Hi,
> My message shows up in encoded form in mailing list archive page. Hence, resending it.
> 
> The bug I filed on this issue was rejected. Details of it can be found here.
> http://rt.cpan.org/Public/Bug/Display.html?id=35942
> 
> The issue is that connections remain open even when out of scope in the latest version of DBIx. Here is the sample code.
> 
> sub connect_to_db {
> my $schema = SchemaClass->connect();
> }
> 
> for (my $i = 0; $i < 10; $i++) {
> connect_to_db();
> }
> print "Press enter to quit\n";
> my $key = <STDIN>;
> 
> DB
> connections should be closed at the end of function call. But, in this
> case you can see the connections remaining open till you provide an
> input the quit.
> 
> I don't have this issue with version 0.07002 of
> DBIx-Class. When I tried tracing program executions with both versions
> of DBIx-class and compared them, I found a code change in
> DBIx/Class/Storage/DBI.pm.
> 
> The latest version has one additional statement in sub '_verify_pid' of DBIx/Class/Storage/DBI.pm.
> 
> sub _verify_pid {
>   my ($self) = @_;
> 
>   return if defined $self->_conn_pid && $self->_conn_pid == $$;
> 
>   $self->_dbh->{InactiveDestroy} = 1;
>   ...
> 
> }
> 
> From
> DBI docs, I understand that if this flag is not set, the dbi handle
> will be destroyed when last reference is removed. If it set, then it
> means 'treat the handle as not-Active in the DESTROY method' and the
> database engine related effects of DESTROYing a handle will be skipped.
> 
> Commenting
> the statement solves the issue I face. But, I am not sure about the
> consequences of it. Could someone tell me what is the significance of
> having this statement in this file and what would be the correct
> solution?

I can't see how this point can be reached without _conn_pid being populated.

Is that a real example script or do you have a fork() involved somewhere?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the DBIx-Class mailing list