Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6068

Thread safety issue in AntBuilder leads to major memory leak

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.7
    • 2.1.3, 2.2.0-beta-1
    • Ant integration
    • None

    Description

      The code in AntBuilder which manipulates the standard input and output stream is not thread safe: https://github.com/groovy/groovy-core/blob/GROOVY_2_0_7/subprojects/groovy-ant/src/main/java/groovy/util/AntBuilder.java#L207

      If 2 or more threads are using AntBuilder at the same time then you end up with System.out or System.err holding a reference to a DemuxOutputStream.

      Unfortunately this class (DemuxOutputStream) ends up (via a long chain of objects) to hold references to AntTypeDefinitions classes which are then never garbage collected.

      After I ran my code for a long time, I used JProfiler and generated the attached screenshot. I had over 180,000 instances of AntTypeDefinitions (and growing...)

      I just checked the trunk on github for groovy-core and can see it is the same code since 2.0.7. So I am assuming it is the same issue.

      Attachments

        1. Groovy6068.groovy
          0.8 kB
          frenchyan
        2. Screen Shot 2013-03-26 at 1.58.54 PM.png
          44 kB
          frenchyan

        Activity

          People

            paulk Paul King
            frenchyan frenchyan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: