HikariCP and Tomcat: Possible Memory Leaks?

3,103 views
Skip to first unread message

Ryan Asleson

unread,
Feb 27, 2014, 3:05:04 PM2/27/14
to hika...@googlegroups.com

Hello,

I'm using HikariCP 1.3.0 in Tomcat 7.  I've noticed messages like these in the Tomcat console:

SEVERE: The web application [/cbr] appears to have started a thread named [Hikari Housekeeping Timer] but has failed to stop it. This is very likely to create a memory leak.

SEVERE: The web application [/cbr] created a ThreadLocal with key of type [com.zaxxer.hikari.util.ConcurrentBag$1] (value [com.zaxxer.hikari.util.ConcurrentBag$1@4c21dfd8]) and a value of type [java.util.LinkedList] (value [[com.zaxxer.hikari.proxy.ConnectionJavassistProxy@535f2cd0]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

Do we need to worry about those?  I've heard that sometimes those Tomcat messages can be safely ignored (Google Guice produces similar errors but according to the Guice guys they can be safely ignored) and I'm just wondering if there is anything special we need to do to prevent memory leaks.  Is there some sort of "stop" method or methods we should be calling when the web app shuts down?

Thank you!!

-Ryan


Brett Wooldridge

unread,
Feb 27, 2014, 11:16:07 PM2/27/14
to hika...@googlegroups.com
You should be calling "shutdown()" on the HikariDataSource at shutdown.  Typically this can be configured through containers like Spring, but I'm not sure what needs to be done in Tomcat.  Having said that, it is possible that even if shutdown() is called there may be a leak, so I will investigate it.  If you can try the shutdown() and report back whether you are still getting logs from Tomcat it would be appreciated.

-Brett

Ryan Asleson

unread,
Feb 28, 2014, 7:54:58 AM2/28/14
to hika...@googlegroups.com
I should have bothered to look for a shutdown() method.  Thanks.

That seems to help, although there still seems to be some strange behavior sometimes, but it's Tomcat, not HikariCP.  I shutdown the data sources from a servlet context listener and I print a message to the console when I do so.  There are times when my shutdown messages appear in the console followed by the Tomcat "possible thread leak" messages, but usually just for Guice.  That's expected.  Other times, Tomcat will start printing out the "possible thread leak" messages before my shutdown messages appear.  So it looks like sometimes Tomcat is doing things out of order, or maybe things are just written to the console out of order, which is possible.

Regardless, the messages have almost completely disappeared and I think any lingering quirks are Tomcat related and not HikariCP.

On a final note, would it be possible to expose the poolName property of the HikariDataSource?  When I'm shutting down the data sources it would be nice to print the names of the pools along with it.  Not a big deal though.

Thank you so much for your help!

-Ryan

Brett Wooldridge

unread,
Feb 28, 2014, 8:24:57 AM2/28/14
to hika...@googlegroups.com
I need to throw the JavaDoc up on the project page somewhere.  I'll also add shutdown() to the FAQ.

I'm checking in a change to the 'dev' branch which will become 1.3.1 when it is released (maybe in a week or so).  What I've done is override the toString() method on the HikariDataSource so that it prints something including the poolName, e.g. "HikariDataSource (MyPool)".

-Brett

Reply all
Reply to author
Forward
0 new messages