[CONJ-61] MySQLStatement does leak TimerThread Created: 2013-08-22 Updated: 2013-09-10 Resolved: 2013-09-05 |
|
| Status: | Closed |
| Project: | MariaDB Connector/J |
| Component/s: | None |
| Affects Version/s: | 1.1.3 |
| Fix Version/s: | 1.1.4 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Torsten Krah | Assignee: | Vladislav Vaintroub |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
JDK 1.7.x, Tomcat 7.0.42 |
||
| Description |
|
Hi, the MySQLStatement does start a TimerThread to handle the timeouts (which are e.g. applied in transactions). Stopping the webapplication does leak those thread because it is never stopped and the complete classloader fails to get garbage collected.
I've done similar for mysql, to stop the scheduler started to destroy connections.
Maybe you can implement similar. And if you do so, it would be nice if you can call the constructor, which does take a name for the Timer, e.g. MariaDBTimeoutStatementTimer, or something like this, to get rid of the "Timer-0" name in the thread overview to know what "Timer-0" is about for. |
| Comments |
| Comment by Vladislav Vaintroub [ 2013-08-22 ] |
|
Why do you think it is a leak? what happens if you start/stop webapp multiple times? How many Timer threads you'll have? |
| Comment by Torsten Krah [ 2013-08-22 ] |
|
The webapp has its own classloader which is pinned in memory because of those thread. The complete classloader fails to be collected because of that, so this is imho called a leak. Tomcat does even tell this: SEVERE: The web application [/] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. If i start the app twice, i get two timer threads, if i do this a third time, i get 3 timer threads and so on - until permgen space runs out of space. |
| Comment by Vladislav Vaintroub [ 2013-09-05 ] |
|
I created a parameterless "unloadDriver" method in the org.mariadb.jdbc.Driver class for this. |
| Comment by Torsten Krah [ 2013-09-09 ] |
|
Can you please give the timer Thread a better name than "Timer"? |
| Comment by Vladislav Vaintroub [ 2013-09-09 ] |
|
It is the name given by the JVM. |
| Comment by Vladislav Vaintroub [ 2013-09-09 ] |
|
I mean, the timer class has the predefined name for this thread and I see no strong reason to give it a special name, even if it would make finding Tomcat classloader bugs easier. |
| Comment by Torsten Krah [ 2013-09-10 ] |
|
To be honest - this has absolutely nothing to do with "obscure tomcat classloading bugs". Tomcat has its boot classloader and every webapp got its own webapp classloader. Any class loaded has a strong reference to its classloader. Imho nothing obscure here - where do you see a tomcat classloading bug? And yes its the name the JDK does assign - but the JDK does also provide a constructor with a "name" arg to just name your timer thread to something meaningful. Just have a look at the http://www.java2s.com/Open-Source/Java-Open-Source-Library/Database/mysql/com/mysql/jdbc/AbandonedConnectionCleanupThread.java.htm code - they are calling the super constructor with a "name" to give their thread a nice name, not only "Thread-0" or something. |