Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

MySQL Resource Leak?

Quote Reply
MySQL Resource Leak?
Hello,

I was wondering if you need to specifically close connection to MySQL whenever you open the connection to the database. Also, is it necessary to clean up $sth by issuing $sth->finish() whenever you call $sth->execute().

Looking at the Links SQL source code, I don't see any closing or cleaning up the connections to MySQL. Does MySQL automatically closes connection at the end of every Perl script? If not, would it cause a resource leak problem for MySQL on a heavy site?

I had a similar problem working on an Access database using ASP, and was wondering how MySQL handles the database connections.

Thanks in advance,

5th season

Quote Reply
Re: MySQL Resource Leak? In reply to
OOOOOOHhhhhh.... how dare you compare MySQL to any windows program! <G>

First, read the documentation on the MySQL.org site, about their windows version. Everyone has cautions and exceptions on the Windows version vs the Unix version. The problem is WINDOWS, not the program in those cases. Even the windows-apache version is considered "beta" code in all the books that have been published (even the ones _just_ published) Why? Windows just is not stable enough to get a stable program out of.

That said.... MySQL will automatically disconnect a session if it has to. (Look in your server log and see if you see any error messages about "program terminated without specifically disconnecting ..." type errors. These are _Warnings_ only. MySQL takes care of it's connections. Partly, it can do this, because it _doesn't_ support transactions, so each connection/request is a separate item. M$ and Oracle do support transactions, so they need to be handled a bit differently. BUT.... if you look in the Links code, if you use DBSQL.pm , there is an exit or clean up routine that will dispose of all handles and connections once that module is released.

You only need to be concerned about programs where you've added in scripts and create your own connections to the database through DBI. One example is if you open a connection to do an UPDATE or INSERT and don't go through any of the DBSQL.pm routines. I had some examples in my code, but can't find them now (of course!). I had short cut the DBSQL.pm creation process for some resaon, and when I looked at the server logs I saw all the warnings. (Maybe I changed the routines... but I'm pretty sure I just added an $sth->disconnect to the end of the program.)

Alex may have warnings specific for M$ platforms, or you may find them at the http://mysql.org site, but on Unix, all that housekeeping is done automatically (as the warnings in the logs show).