Memory leak in Asset Share Commons search

Issue

During stress test of asset search of asset share commons [1], a memory leak or unresolved object issue happened.

Steps to reproduce:

  1. Install AEM6.3, SP1 and CFP2

  2. Install asset-share-commons.ui.apps-1.1.2.zip (happens even on 1.4.0)

  3. Install asset-share-commons.ui.content-1.1.2.zip (happens even on 1.4.0)

  4. Create a page "search template" on "Asset Share Commons" on Sites

  5. Run "Search" with any word including blank, hundreds times.

  6. Or run this command:

    # ab -n 100 -c 1 -A admin:admin "http://localhost:4502/content/asset-share-commons/en/light/searchtestpage.html?layout=card&p.offset=0&p.limit=24"

    Even after Full Java GC happens, some objects cannot be released.

    # jcmd 1810 GC.class_histogram | grep AssetResult
    505: 169 6760 com.adobe.aem.commons.assetshare.search.results.impl.result.AssetResultImpl
    # jcmd 1810 GC.class_histogram | grep AssetResult
    189: 1608 64320 com.adobe.aem.commons.assetshare.search.results.impl.result.AssetResultImpl

    A heap dump analysis tells a suspect is org.apache.sling.models.impl.ModelAdapterFactory loaded by org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 [2].

    1. https://github.com/Adobe-Marketing-Cloud/asset-share-commons
    2. One instance of "org.apache.sling.models.impl.ModelAdapterFactory" loaded by "org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 @ 0x9749d5d0" occupies 1,528,764,960 (78.49%) bytes. The memory is accumulated in one instance of "org.apache.sling.models.impl.ModelAdapterFactory" loaded by "org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 @ 0x9749d5d0".

      Keywords
      org.apache.sling.models.impl.ModelAdapterFactory
      org.apache.felix.framework.BundleWiringImpl$BundleClassLoaderJava5 @ 0x9749d5d0

Environment

AEM 6.3 SP1-CFP2 with Asset Share Commons 1.1.2 and earlier versions.

Cause

There was a problem in Asset Share Commons. The QueryBuilder search creates unclosed ResourceResolver.

Resolution

Update Asset Share Commons to version 1.1.4 or later.