Bug #69526 'Abandoned connection cleanup thread' at mysql-connector-java-5.1.25
Submitted: 20 Jun 2013 17:49 Modified: 7 Feb 2017 0:21
Reporter: bruce liang Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:5.1.25 OS:Any
Assigned to: Filipe Silva CPU Architecture:Any
Tags: Abandoned connection cleanup thread

[20 Jun 2013 17:49] bruce liang
org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/XXX] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

How to repeat:
every time shutting down tomcat

Suggested fix:
this bug appear at mysql-connector-java-5.1.25 (but mysql-connector-java-5.1.24 not yet)
[21 Jun 2013 9:43] MySQL Verification Team
Looks like reported in Bug #68556
[21 Jun 2013 9:53] Filipe Silva
Thanks for your report, Bruce.

Could you please check the note regarding Bug#68556 in c/J 5.1.25 release notes (http://dev.mysql.com/doc/relnotes/connector-j/en/news-5-1-25.html): «Tomcat would fail to stop abandoned connection cleanup threads. The fix for Bug#65909 introduced the ability to stop daemon threads started by the Connector/J driver but it also cleared references from daemon threads to the parent classloader. When the clearReferencesStopThreads property is set to “true” in context.xml, Tomcat analyzes classloaders to detect and stop lost threads. This fix ensures that abandoned connection cleanup threads retain a reference to the parent classloader. (Bug #68556, Bug #16443387)», and inform us of result?

We are currently working on related Bug#69229. Feel free to track this report and add the comments you see fit.
[28 Jun 2013 15:36] bruce liang
Not Work !!
Even if if add the "clearReferencesStopThreads"attribute to context.xml (<Context clearReferencesStopThreads="true">), memory leak warning message is still appear like this:

org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/XXX] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

  My tomcat version is 7.0.39, and why this problem doesn't happen in mysql-connector-java-5.1.24 ??
[1 Jul 2013 9:00] Alexander Soklakov
Hi Bruce,

There are several negative feedbacks about our fix of Bug#68556, please look there for comments and proposed workaround.

Also, please, say do you implement WebListener proposed in Bug#65909 fix or just use Tomcat built-in functionality.

Verified as regression of Bug#68556.
[11 Sep 2014 7:42] Alexander Soklakov
Bug#73876 was marked as a duplicate of this one. Please, look there for Christopher Schultz' proposal.
[7 Feb 2017 0:21] Daniel So
Posted by developer:
Added the follow entry to the Connector/J 5.1.41 changelog:

" When using Tomcat and a web application that utilized Connector/J was down, Tomcat was unable to stop the AbandonedConnectionCleanupThread started internally by Connector/J, leading to multiple instances of the thread when the web application was restarted; or, Tomcat was able to stop the thread but unable to restart it on reload of the web application. Different combinations of Tomcat's default settings, usage of Tomcat's ServletContextListener feature, and locations of the Connector/J jar could result in the undesired behaviors, as well as warning messages in the Tomcat error log saying it was unable to stop the thread and a memory leak was likely.

The implementation of AbandonedConnectionCleanupThread has now been improved, so that there are now four ways for developers to deal with the situation:

- When the default Tomcat configuration is used and the Connector/J jar is put into a local library directory, the new built-in application detector in Connector/J now detects the stopping of the web application within 5 seconds and kills AbandonedConnectionCleanupThread. Any unnecessary warnings about the thread being unstoppable are also avoided. If the Connector/J jar is put into a global library directory, the thread is left running until the JVM is unloaded.

- When Tomcat's context is configured with the attribute clearReferencesStopThreads="true", Tomcat is going to stop all spawned threads when the application stops unless Connector/J is being shared with other web applications, in which case Connector/J is now protected against an inappropriate stop by Tomcat; the warning about the non-stoppable thread is still issued into Tomcat's error log.

- When a ServletContextListener is implemented within each web application that calls AbandonedConnectionCleanupThread.checkedShutdown() on context destruction, Connector/J now, again, skips this operation if the driver is potentially shared with other applications. No warning about the thread being unstoppable is issued to Tomcat's error log in this case.

- When AbandonedConnectionCleanupThread.uncheckedShutdown() is called the AbandonedConnectionCleanupThread is closed even if Connecotr/J is shared with other applications. However, it may not be possible to restart the thread afterwards. "