develooper Front page | perl.dbi.users | Postings from December 2012

Re: Possible database handle leak in DBI?

Thread Previous | Thread Next
Greg Sabino Mullane
December 5, 2012 02:34
Re: Possible database handle leak in DBI?
Message ID:

Hash: RIPEMD160

Duncan McEwan wrote:
> Our application uses the DBI connect_cached() method so that it can reuse
> a persistent database connection for each invocation.
> Unfortunately I don't understand well enough to know how an item
> could drop out of the cache while the corresponding database connection
> remains active.

So to summarize, you are seeing that sometimes connect_cached uses 
a previous entry, and sometimes it does not, right? If it does it 
every time, then something is preventing the cache from being used 
at all, but it sounds like it is an occasional event. When the 
connect_cached fails with a false negative, it is because the CachedKids 
hash is empty, when it should have at least one existing item, right?

I'd bump up the trace level to at least 3, or at least check out the 
clear_cached_kids function inside of DBI.xs and get some debugging 
there to see who is clearing that cache. As far as DBI itself, I 
think only destroying a handle will call that function, and that 
function is the only thing that will empty out {CachedKids}. It's 
possible that the cache is getting cleared before the database handle 
truly dies and does a full disconnect.

I don't see any mention of CachedKids or clear_cached_kids inside 
DBD::mysql, so we can probably rule that out. The other thing to 
consider is the web app. I know that Apache::DBI / modperl has a 
lot of special rules regarding connecting and reconnecting: it's 
possible your fastcgi does as well.

You might also want to poke around with the mysql_auto_reconnect 
setting; it's possible it is on and causing issues.

- -- 
Greg Sabino Mullane
End Point Corporation
PGP Key: 0x14964AC8 201212042128



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About