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

Thread safety issue in AntBuilder leads to major memory leak

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.7
    • Fix Version/s: 2.1.3, 2.2.0-beta-1
    • Component/s: Ant integration
    • Labels:
      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

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: