DB - Connection Leak

DB Connection - Connection Leak

A connection leak happens when a connection is acquired without ever being closed.This kind of mistakes which usually we do by making the the boolean close Connection is setted to be false , it causes a problem where the connection will not be closed after the sql is executed.

It actually appears in our code as ....

boolean closeConnection = false;

And this false boolean value make the database connection not to be freed to use by the another request which is waiting in the queue by executing the final statement ...

finally {

                    db.releaseResources(closeConnection);

             }

As result the resource utilization like heap,CPU will be linearly increasing and the number of established DB connection which can be reused and the number of Busy DB connection which cannot be reused will travel in the same line bcoz of the false boolean value.This kind of the behavior can be easily identified by the server admin tools.

Detecting connection leaks is a mandatory requirement for every enterprise application. While you can find scripts which run periodically and kill all idle database connections, this is just a band aid approach.The best way to deal with connection leaks is to fix the underlying code base so that connections are always closed properly. To make sure that the production environment is connection leak free, every integration test must validate that no connection is being leaked by the actual tested source code or by the testing logic itself.


要查看或添加评论,请登录

社区洞察

其他会员也浏览了