Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2195

Memory leak in XMLReaderManager

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Blocker
    • Resolution: Unresolved
    • 2.7
    • None
    • Xalan
    • None

    Description

      In class org.apache.xml.utils.XMLReaderManager

      getXMLReader() method creates a new XMLReader (i.e. SAXParser) and stores it into ThreadLocal.

      releaseXMLReader() does not remove (set to null) ThreadLocal thus creating a permanent leak.

      Unfortunately the size of the cached Reader is typically dependent upon the size of the XML document you process (depends on implementation but this is the case with xerces SAXParser). In heavy load server environments with thread pools of tens and hundreds of threads the server sustains a significant memory leak (hundreds of megabytes - depending on the XML document sizes and number of threads in a thread pools).

      A fix is trivial:

      Put the following line at the end of releaseXMLReader method:

      m_readers.set(null);

      I wonder, why is reader stored in ThreadLocal in the first place?

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            mstruk Marko Strukelj

            Dates

              Created:
              Updated:

              Slack

                Issue deployment