JCR Session leaks reported in logs | AEM 6.x

Issue

In the AEM error.log log messages report Unclosed session detected. For example, in the example below [1] you can see a session leak in this code:

com.day.cq.dam.scene7.impl.listener.Scene7AssetActivationListener.searchViewerWidgets(Scene7AssetActivationListener.java:306)

In this case, the sessions leak originates from the creation of an administrative ResourceResolver:

org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getAdministrativeResourceResolver(ResourceResolverFactoryImpl.java:107)

However, the same can happen when opening an administrative session, service resolver, or service session.

[1] Example session leak

WARN [Finalizer] org.apache.jackrabbit.core.SessionImpl Unclosed session detected. The session was opened here: java.lang.Exception: Stack Trace
at org.apache.jackrabbit.core.SessionImpl.<init>(SessionImpl.java:222)
at org.apache.jackrabbit.core.XASessionImpl.<init>(XASessionImpl.java:117)
at com.day.crx.core.CRXSessionImpl.<init>(CRXSessionImpl.java:69)
at com.day.crx.core.CRXRepositoryImpl.createSessionInstance(CRXRepositoryImpl.java:935)
at org.apache.jackrabbit.core.RepositoryImpl.createSession(RepositoryImpl.java:959)
at org.apache.jackrabbit.core.SessionFactory.createAdminSession(SessionFactory.java:42)
at com.day.crx.sling.server.impl.SlingRepositoryWrapper.loginAdministrative(SlingRepositoryWrapper.java:76)
at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.getResourceProviderInternal(JcrResourceProviderFactory.java:136)
at org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory.getAdministrativeResourceProvider(JcrResourceProviderFactory.java:115)
at org.apache.sling.resourceresolver.impl.tree.ResourceProviderFactoryHandler.login(ResourceProviderFactoryHandler.java:162)
at org.apache.sling.resourceresolver.impl.tree.RootResourceProviderEntry.loginToRequiredFactories(RootResourceProviderEntry.java:95)
at org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getResourceResolverInternal(ResourceResolverFactoryImpl.java:98)
at org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getAdministrativeResourceResolver(ResourceResolverFactoryImpl.java:72)
at org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext.getResourceTypeResourceResolver(ResourceResolverContext.java:192)
at org.apache.sling.resourceresolver.impl.helper.ResourceResolverContext.getParentResourceType(ResourceResolverContext.java:216)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getParentResourceType(ResourceResolverImpl.java:1136)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.getParentResourceType(ResourceResolverImpl.java:1126)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.isResourceType(ResourceResolverImpl.java:1151)
at org.apache.sling.api.resource.AbstractResource.isResourceType(AbstractResource.java:115)
at com.day.cq.dam.scene7.impl.listener.Scene7AssetActivationListener.searchViewerWidgets(Scene7AssetActivationListener.java:306)

Resolution

If the code that creates the session is AEM, Sling or Oak product code, then contact AEM Customer Care.

If it is in custom code, the solution is to logout of the Session or close the ResourceResolver when you're done using it.

Example of session being opened and closed:

Session session = null;
try {
  session = repository.getService("readService",null);
  // use session
} finally {
  if(session != null && session.isLive()) {
    session.logout();
  }
}

Example of ResourceResolver being opened and closed:

ResourceResolver resolver = null;
try {
  resolver = resourceFactory.getServiceResourceResolver(paramMap); 
  // use resolver
} finally {
  if(resolver != null && resolver.isLive()){
    resolver.close();
  }
}

 Adobe

Получете помощ по-бързо и по-лесно

Нов потребител?