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

MySQLStatement does leak TimerThread

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 1.1.3
    • 1.1.4
    • None
    • None
    • 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

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

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.