Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-61

MySQLStatement does leak TimerThread

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1.3
    • Fix Version/s: 1.1.4
    • Component/s: None
    • 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.
      My current workaround is, to call this in the contextDestroyed method of a webapp listener:

          try {
            final Class<?> clazz = ReflectionUtils.getClassForName("org.mariadb.jdbc.MySQLStatement");
            final Field f = clazz.getDeclaredField("timer");
            f.setAccessible(true);
            Timer timer = (Timer) f.get(null);
            if (timer != null) {
              timer.cancel();
            }
            timer = null;
          } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
            // ignore
          }
      

      I've done similar for mysql, to stop the scheduler started to destroy connections.
      The difference is that there is an api call, a static method shutdown, to do this and i need no hacks to get that timer variable.

          try {
            final Class<?> clazz = ReflectionUtils.getClassForName("com.mysql.jdbc.AbandonedConnectionCleanupThread");
            MethodUtils.invokeExactStaticMethod(clazz, "shutdown", null);
          } catch (ClassNotFoundException e) {
            // ignore
          } catch (NoSuchMethodException e) {
            // ignore
          } catch (IllegalAccessException e) {
            // ignore
          } catch (InvocationTargetException e) {
            // ignore
          }
      

      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.

        Attachments

          Activity

            People

            • Assignee:
              wlad Vladislav Vaintroub
              Reporter:
              tkrah Torsten Krah
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h