Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Unclosed session detected in logs

Avatar

Level 3

I am getting an unclosed session detected warning in the error.log . I have opened and closed all the sessions in the finally block. Still I am getting the warning. It has made the author instance very slow due to large number of unclosed session . Here are the error logs

 

04.06.2015 02:45:54.921 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.(SessionImpl.java:222) at org.apache.jackrabbit.core.XASessionImpl.(XASessionImpl.java:117) at com.day.crx.core.CRXSessionImpl.(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:95) at org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getAdministrativeResourceResolver(ResourceResolverFactoryImpl.java:69) 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.ResourceUtil.isA(ResourceUtil.java:466) at com.adobe.cq.social.storage.index.AbstractBaseIndexHandler.checkResourceType(AbstractBaseIndexHandler.java:111)

This is the code snippet after which we get this warning.

private List<String>  rollOutPages(Collection<Page> pages) throws Exception{final ResourceResolver adminResourceResolver =  resourceResolverFactory.getAdministrativeResourceResolver(null); List<String> rolledOutPages = new ArrayList<>();try {//adminResourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);        for (Page page : pages) {final Collection<LiveRelationship> liveRelationships = relationShipManager.getLiveRelationships(page, null, null, false);for (LiveRelationship relationship : liveRelationships) {rolloutManager.rollout(adminResourceResolver, relationship, false); rolledOutPages.add(relationship.getTargetPath()); } } adminResourceResolver.adaptTo(Session.class).save(); adminResourceResolver.adaptTo(Session.class).logout(); adminResourceResolver.close();return rolledOutPages; }catch (WCMException e) { adminResourceResolver.adaptTo(Session.class).save(); adminResourceResolver.adaptTo(Session.class).logout(); adminResourceResolver.close();LOG.error("Unable to create administrative resource resolver", e);throw new AbortException("Exception during rollout of pages",e.getMessage()); }catch (Exception e) { adminResourceResolver.adaptTo(Session.class).save(); adminResourceResolver.adaptTo(Session.class).logout(); adminResourceResolver.close();LOG.error("Exception during rollout of pages", e);throw new AbortException("Exception during rollout of pages",e.getMessage()); }finally {if(adminResourceResolver.isLive()||adminResourceResolver != null){ adminResourceResolver.close(); } } }

 

I have closed the session in the finally block. Still getting this warning. Can anybody please help me in understanding what am I missing here. Thanks

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi,

I assume that you are using AEM 5.6.1; please raise a Daycare ticket and ask how to deal with this. The problem is within the some code shipped with the product.

This message has nothing to do with your own code. Your code might trigger the check, but when you read the message thoroughly, it just says, that a session has been left unclosed, and that this session has been opened by a thread with the printed stacktrace.

kind regards,
Jörg

View solution in original post

5 Replies

Avatar

Level 2

How long does it take for this piece of code to execute? AFAIK this warning get displayed in logs after certain amount of time elapsed. So if your code is taking long to run (and since it's rolling out Live Copies I'm guessing it's not THE quickest one ;) )  Btw your code is going to fail in case your adminResourceResolver is null, as you are first trying to run isLive on it, and then you check if it's not null. Also you don't need to close RR so many times :) Single line of code in finally block will be more than enough. 

Avatar

Correct answer by
Employee Advisor

Hi,

I assume that you are using AEM 5.6.1; please raise a Daycare ticket and ask how to deal with this. The problem is within the some code shipped with the product.

This message has nothing to do with your own code. Your code might trigger the check, but when you read the message thoroughly, it just says, that a session has been left unclosed, and that this session has been opened by a thread with the printed stacktrace.

kind regards,
Jörg

Avatar

Level 3

Hi Tomasz Sobczyk

 

Thanks for your reply. I will make the check for running first isNull and then isLive on the adminresolver. Yes there are a lot of pages getting rolled out(around 40-50) . I wanted to know if this issue can be because the RR not getting closed properly. The session is opened several times in the code (not just in this snippet) and is closed in the same way as it is closed here. It has severely hampered the performance of the system

Avatar

Level 2

You could also do some steps on your own. Please follow this to analyze source of unclosed sessions. One thing it's going to give you is the number of unclosed sessions. Secondly you can analyze stack traces of those open sessions to see exactly where was the session opened.

https://helpx.adobe.com/experience-manager/kb/AnalyzeUnclosedSessions.html

Avatar

Level 3

Hi experts,

 

Thanks for you reply. I will check for the mentioned link for unclosed session and will write down the analysis.