Expand my Community achievements bar.

Resource resolver is already closed exception when under load

Avatar

Level 5

When we are load testing a servlet in CQ5 I am seeing lots of Resource resolver is already closed exceptions, stack trace below. I'm not sure why this is occuring and only when the code is under load, the code that is causing the issue is:

Resource resource = request.getResourceResolver().resolve(ConstantClass.A_NODE);

the request is simply being passed in as part of the doGet method, set to a class level variable and later used in the code above. 

The stack trace is:

java.lang.IllegalStateException.Resource resolver is already closed.
      at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.checkClosed(ResourceResolverImpl.java:169)
      at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.resolve(ResourceResolverImpl.java:201)
      at com.myCode(myClass.java:142)
      at org.apache.sling.api.servlets.SlingSafeMethodsServlet.mayService(SlingSafeMethodsServlet.java:268)
      at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:139)
      at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:344)
      at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:375)
      at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508)
      at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
      at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:148)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:333)
      at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:160)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:254)
      at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:64)
      at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:106)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:290)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.collab.wiki.impl.WikiMailServiceImpl.doFilter(WikiMailServiceImpl.java:552)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.collab.wiki.impl.WikiServiceImpl.doFilter(WikiServiceImpl.java:440)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:59)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:220)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.theme.impl.ThemeResolverFilter.doFilter(ThemeResolverFilter.java:76)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:74)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter.doFilter(CanvasPageDeleteRequestFilter.java:87)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:83)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:127)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter.doFilter(BackgroundServletStarterFilter.java:135)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:60)
      at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processRequest(SlingRequestProcessorImpl.java:151)
      at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:206)
      at org.apache.felix.http.base.internal.handler.ServletHandler.doHandle(ServletHandler.java:96)
      at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:79)
      at org.apache.felix.http.base.internal.dispatch.ServletPipeline.handle(ServletPipeline.java:42)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:49)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:127)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at com.adobe.granite.license.impl.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:179)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:259)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:55)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:75)
      at org.apache.felix.http.base.internal.handler.FilterHandler.doHandle(FilterHandler.java:88)
      at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:76)
      at org.apache.felix.http.base.internal.dispatch.InvocationFilterChain.doFilter(InvocationFilterChain.java:47)
      at org.apache.felix.http.base.internal.dispatch.HttpFilterChain.doFilter(HttpFilterChain.java:33)
      at org.apache.felix.http.base.internal.dispatch.FilterPipeline.dispatch(FilterPipeline.java:48)
      at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:39)
      at org.apache.felix.http.base.internal.DispatcherServlet.service(DispatcherServlet.java:67)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      at com.day.j2ee.servletengine.ServletRuntimeEnvironment.service(ServletRuntimeEnvironment.java:250)
      at com.day.j2ee.servletengine.RequestDispatcherImpl.doFilter(RequestDispatcherImpl.java:321)
      at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:340)
      at com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:383)
      at com.day.j2ee.servletengine.ServletHandlerImpl.process(ServletHandlerImpl.java:360)
      at com.day.j2ee.servletengine.HttpListener$Worker.run(HttpListener.java:644)
      at java.lang.Thread.run(Thread.java:736)
 
7 Replies

Avatar

Administrator

Hi

Please have a look at the similar old thread :

Link:-http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

//This issue occurs when you are trying to use the session / resource resolver which is already closed and instead of creating a new session, you are trying to refer an old object.

I hope this will help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 5

I don't think I am pointing to a refrence that has already been closed, I am using the request and response objects passed into the servlet like so:

 

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException{ this.request = request; this.response = response; run(); }

Those request and response objects are then set as class level variables...I'm worrying somehow this is not threadsafe?

Avatar

Level 9

Yes. That is not a correct way. Is there any specific need to make them global variables?.

--Jitendra

Avatar

Level 5

No there is no real need, this is certainly the cause of my issues I've moved them to method level variables 

Avatar

Level 10

What exactly are you trying to do in your AEM Servlet - are you trying to read JCR resources?  Purhaps we have a community article that shows you hwo to do this.

Avatar

Level 2

HI smacdonald2008,

can you please provide that community article link here.

Avatar

Level 9

So, did you get your issue resolved?.

Sutty100 wrote...

No there is no real need, this is certainly the cause of my issues I've moved them to method level variables