Lucene - Core
  1. Lucene - Core
  2. LUCENE-2260

AttributeSource holds strong reference to class instances and prevents unloading e.g. in Solr if webapplication reload and custom attributes in separate classloaders are used (e.g. in the Solr plugins classloader)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.9.1, 3.0
    • Fix Version/s: 2.9.2, 3.0.1, 4.0-ALPHA
    • Component/s: None
    • Labels:
      None
    • Lucene Fields:
      New, Patch Available

      Description

      When working on the dynmaic proxy classes using cglib/javaassist i recognized a problem in the caching code inside AttributeSource:

      • AttributeSource has a static cache map that holds implementation classes for attributes to be faster on creating new attributes (reflection cost)
      • AttributeSource has a static cache map that holds a list of all interfaces implemented by a specific AttributeImpl

      Also:

      • VirtualMethod in 3.1 hold a map of implementation distances keyed by subclasses of the deprecated API

      Both have the problem that this strong reference is inside Lucene's classloader and so persists as long as lucene lives. The classes referenced can never be unloaded therefore, which would be fine if all live in the same classloader. As soon as the Attribute or implementation class or the subclass of the deprecated API are loaded by a different classloder (e.g. Lucene lives in bootclasspath of tomcat, but lucene-consumer with custom attributes lives in a webapp), they can never be unloaded, because a reference exists.

      Libs like CGLIB or JavaAssist or JDK's reflect.Proxy have a similar cache for generated class files. They also manage this by a WeakHashMap. The cache will always work perfect and no class will be evicted without reason, as classes are only unloaded when the classloader goes and this will only happen on request (e.g. by Tomcat).

      1. LUCENE-2260.patch
        7 kB
        Uwe Schindler
      2. LUCENE-2260.patch
        4 kB
        Uwe Schindler
      3. LUCENE-2260-lucene29.patch
        5 kB
        Uwe Schindler

        Activity

        Hide
        Uwe Schindler added a comment -

        Attached patch. I will commit this in a day and also merge to 2.9 and 3.0 (without VirtualMethod) as this is a resource leak. This problem is similar to LUCENE-2182.

        Show
        Uwe Schindler added a comment - Attached patch. I will commit this in a day and also merge to 2.9 and 3.0 (without VirtualMethod) as this is a resource leak. This problem is similar to LUCENE-2182 .
        Hide
        Uwe Schindler added a comment -

        Improved patch, now all class references are weak. The assumption on the WeakReference inside addAttributeImpl is always != null is true because the code has a strong reference on the implementing class.

        Show
        Uwe Schindler added a comment - Improved patch, now all class references are weak. The assumption on the WeakReference inside addAttributeImpl is always != null is true because the code has a strong reference on the implementing class.
        Hide
        Uwe Schindler added a comment -

        Patch for 2.9 branch (without Java 5 generics)

        Show
        Uwe Schindler added a comment - Patch for 2.9 branch (without Java 5 generics)
        Hide
        Uwe Schindler added a comment -

        I'll commit this soon!

        Show
        Uwe Schindler added a comment - I'll commit this soon!
        Hide
        Uwe Schindler added a comment -

        Committed trunk revision: 909360
        Committed 2.9 revision: 909361
        Committed 3.0 revision: 909365

        Show
        Uwe Schindler added a comment - Committed trunk revision: 909360 Committed 2.9 revision: 909361 Committed 3.0 revision: 909365

          People

          • Assignee:
            Uwe Schindler
            Reporter:
            Uwe Schindler
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development