groovy
  1. groovy
  2. GROOVY-5187

Groovy Script Engine creates new classes for each script and doesn't get garbage collected

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.4, 2.0-beta-1
    • Fix Version/s: 2.0.6, 1.8.9
    • Component/s: GroovyScriptEngine
    • Labels:
      None
    • Number of attachments :
      0

      Description

      New classes are created for each script:

      https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java#L109

      Which are added to the classMap, which grows and old classes don't get garbage collected:

      https://github.com/groovy/groovy-core/blob/master/src/main/org/codehaus/groovy/jsr223/GroovyScriptEngineImpl.java#L338

      This results in PermGen errors:

      Rexster Groovy Script Engine
      https://github.com/tinkerpop/rexster/issues/143

      Neo4j Server Groovy Script Engine
      http://neo4j-community-discussions.438527.n3.nabble.com/Neo4j-Feedback-after-evaluation-tp3569774p3574520.html

      There is no public way of removing older scripts and the HashMap is not a LinkedHashMap with LRU enabled for storing them. Right now the Neo4j workaround is to recreated the GSE every 500 requests.

        Activity

        Hide
        blackdrag blackdrag added a comment -

        I made the map a soft reference based one. It can now forget entries over time. OOME can still happen of course, since class unloading is not always done as it should by the JVM, but the cases are very much reduced. This solution is kind of a middle ground. A LRU could still cause OOME, on the other hand the engine is originally not created to forget classes.

        Show
        blackdrag blackdrag added a comment - I made the map a soft reference based one. It can now forget entries over time. OOME can still happen of course, since class unloading is not always done as it should by the JVM, but the cases are very much reduced. This solution is kind of a middle ground. A LRU could still cause OOME, on the other hand the engine is originally not created to forget classes.
        Hide
        blackdrag blackdrag added a comment -

        Because of me taking the wrong map GROOVY-5706 was filled and that has a major effect on the fix released in 1.8.8 and 2.0.2, till the point the jsr223 module my not really work anymore. Thus a new fix was required, changing the fix version for this issue

        Show
        blackdrag blackdrag added a comment - Because of me taking the wrong map GROOVY-5706 was filled and that has a major effect on the fix released in 1.8.8 and 2.0.2, till the point the jsr223 module my not really work anymore. Thus a new fix was required, changing the fix version for this issue
        Hide
        blackdrag blackdrag added a comment -

        As there have been a conflict with GROOVY-5786 this feature now has to be activated. that means the engine will by default not forget global functions and attached classes. See http://groovy.codehaus.org/JSR+223+Scripting+with+Groovy for how to activate it

        Show
        blackdrag blackdrag added a comment - As there have been a conflict with GROOVY-5786 this feature now has to be activated. that means the engine will by default not forget global functions and attached classes. See http://groovy.codehaus.org/JSR+223+Scripting+with+Groovy for how to activate it

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            James Thornton
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: