Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JRuby org.joni.StackMachine is not correctly unloaded from ThreadLocal - possible MemLeak #920

Closed
keklabs opened this issue Jul 26, 2013 · 2 comments

Comments

@keklabs
Copy link

keklabs commented Jul 26, 2013

We use Jruby 1.7.4 in simple servlet like this (on Tomcat 7.0.42, Oracle JDK 7u25):

public class RubyServlet extends HttpServlet {

  private static final long serialVersionUID = 5609571251958664412L;

  @Override
  protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    String script = req.getParameter("ruby-script");

    ScriptingContainer scriptingContainer = new ScriptingContainer(LocalContextScope.SINGLETHREAD, LocalVariableBehavior.TRANSIENT);
    try{
    scriptingContainer.setCompileMode(org.jruby.RubyInstanceConfig.CompileMode.OFF);
    scriptingContainer.setCompatVersion(CompatVersion.RUBY1_9);
    scriptingContainer.setRunRubyInProcess(false);
    RubyInstanceConfig config = scriptingContainer.getProvider().getRubyInstanceConfig();
    config.setCextEnabled(false);
    config.setHardExit(false);
    config.setNativeEnabled(false);
    config.setRunRubyInProcess(false);
    config.setShouldCheckSyntax(true);
    config.setUpdateNativeENVEnabled(false);
    Object result = scriptingContainer.runScriptlet(script);

    resp.getWriter().format("Result is: %s", result);
    }finally{
      scriptingContainer.terminate();
    } 
  }
}

In my opinion all allocated resources should be released in scriptingContainer.terminate(), but when we shutdown the Tomcat instance, we got following warnings:

VII 26, 2013 6:57:35 DOP. org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
VII 26, 2013 6:57:36 DOP. org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/test] appears to have started a thread named [FileWatchdog] but has failed to stop it. This is very likely to create a memory leak.
VII 26, 2013 6:57:36 DOP. org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/test] created a ThreadLocal with key of type [org.joni.StackMachine$1] (value [org.joni.StackMachine$1@13ec94f]) and a value of type [java.lang.ref.WeakReference] (value [java.lang.ref.WeakReference@112871a]) 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.
VII 26, 2013 6:57:36 DOP. org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/test] created a ThreadLocal with key of type [org.joni.StackMachine$1] (value [org.joni.StackMachine$1@13ec94f]) and a value of type [java.lang.ref.WeakReference] (value [java.lang.ref.WeakReference@163d93b]) 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.
VII 26, 2013 6:57:36 DOP. org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/test] created a ThreadLocal with key of type [org.joni.StackMachine$1] (value [org.joni.StackMachine$1@13ec94f]) and a value of type [java.lang.ref.WeakReference] (value [java.lang.ref.WeakReference@4ae99f]) 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.
VII 26, 2013 6:57:36 DOP. org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
VII 26, 2013 6:57:36 DOP. org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8042"]

This could cause problems when we want redeploy some WAR file with ruby without Tomcat restart.
Please, clean up the internal ThreadLocals (or correctly terminate the used StackMachine) from scriptingContainer.terminate()

Thanks very much

@keklabs
Copy link
Author

keklabs commented Jul 26, 2013

I´m not sure where issues are managed, so I put this issue to Jira too:
https://jira.codehaus.org/browse/JRUBY-7187

@kares
Copy link
Member

kares commented Oct 10, 2016

has been resolved (at some point) already with changes such as #1772

@kares kares closed this as completed Oct 10, 2016
@kares kares added this to the Invalid or Duplicate milestone Oct 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants