Tomcat JDBC Pool — Connection Leaks — Catch the Culprit

Pushpalanka Jayawardhana
3 min readApr 28, 2020

Database connection leaks are something that can stay hidden unless paid specific attention and would come to the surface at the most critical stages at a peak time of the system. We would manually check if all the open connections have been closed properly. Then we have various code quality plugins that would scan and check for that. Still when the connections are passed through a complex structure of program both of these can miss a possible connection leak. Then at unit test or integration test levels, we can have checks to validate the counts in the connection pool to avoid this unfortunate situation, that would keep engineers busy at year-end, black Friday, etc. :)

In the unfortunate case of hitting with a performance degrade or a total crash of the system which can be propagated via a JDBC connection leak or when we just suspect a connection leak, how easily and quickly can we isolate the culprit? In the Tomcat connection pool, we can do this using 3 properties as below.

removeAbandoned

If a DB connection has been abandoned(not been used for a while, but haven’t returned to the pool), this configuration will try to remove it. How long to wait before it removes the connection is configured by the below configuration.

removeAbandonedTimeout

The time it will spare before attempting to remove the connection. By default 60s.

--

--