Expand my Community achievements bar.

AEM : org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl Unclosed ResourceResolver was created here: java.lang.Exception

Avatar

Level 1

Hi Team,

 

I am getting the below error in our live environment and not getting in lower environments and not sure when are we getting and how to replicate them.

 

We are using AEM 6.5.19. Please let us  know if anyonefacing the same and suggest a fix for this please

 

07.03.2024 08:52:49.225 *INFO* [FelixStartLevel] org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl Unclosed ResourceResolver was created here:
java.lang.Exception: Opening Stacktrace
at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl$ResolverReference.<init>(CommonResourceResolverFactoryImpl.java:538)
at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.register(CommonResourceResolverFactoryImpl.java:228)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.<init>(ResourceResolverImpl.java:113)
at org.apache.sling.resourceresolver.impl.ResourceResolverImpl.<init>(ResourceResolverImpl.java:106)
at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.getResourceResolverInternal(CommonResourceResolverFactoryImpl.java:273)
at org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl.getResourceResolver(CommonResourceResolverFactoryImpl.java:183)
at org.apache.sling.resourceresolver.impl.ResourceResolverFactoryImpl.getResourceResolver(ResourceResolverFactoryImpl.java:98)
at com.day.cq.dam.indd.process.INDDMediaExtractProcess.getResourceResolver(INDDMediaExtractProcess.java:427)
at com.day.cq.dam.indd.process.INDDMediaExtractProcess.execute(INDDMediaExtractProcess.java:164)
at com.day.cq.workflow.compatibility.CQWorkflowExtProcessProxy.execute(CQWorkflowExtProcessProxy.java:66)
at com.adobe.granite.workflow.core.util.WEPProxyHolder.execute(WEPProxyHolder.java:42)
at com.adobe.granite.workflow.core.job.JobHandler.process(JobHandler.java:292)
at org.apache.sling.event.impl.jobs.JobConsumerManager$JobConsumerWrapper.process(JobConsumerManager.java:502)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.startJob(JobQueueImpl.java:351)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl.access$100(JobQueueImpl.java:60)
at org.apache.sling.event.impl.jobs.queues.JobQueueImpl$1.run(JobQueueImpl.java:287)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

2 Replies

Avatar

Community Advisor

The error you're encountering in your live environment on AEM 6.5.19, related to an unclosed ResourceResolver, is a common issue that can lead to memory leaks and performance degradation if not addressed properly. This error indicates that a ResourceResolver instance was created but not properly closed after its use. The ResourceResolver should always be closed in a finally block or using a try-with-resources statement to ensure it gets closed even if an exception occurs.

Since you're not experiencing this issue in lower environments, it might be related to specific conditions or workflows in your live environment. It could be triggered by custom code, workflows, or specific asset processing tasks that are not executed or tested in your lower environments.

To address this issue, you should:

  1. Review Custom Code: Check any custom code or scripts that obtain a ResourceResolver instance, especially around the areas indicated by the stack trace (e.g., custom workflow steps, event listeners, or scheduled jobs). Ensure that every ResourceResolver is properly closed.

  2. Use Try-With-Resources: For any new code or when updating existing code, use the try-with-resources statement to manage the ResourceResolver. This Java feature automatically handles the closing of resources and makes your code cleaner and safer. Here's an example pattern for using ResourceResolver within a try-with-resources statement:

    java
    try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(paramMap)) {
        // Your code that uses the resolver here
    } catch (LoginException e) {
        // Handle potential exceptions here
    }
  3. Investigate Workflows and Processes: Given the stack trace points to INDDMediaExtractProcess, review any custom Adobe InDesign document (INDD) media extraction processes you have. There might be an oversight in resource management within these processes.

  4. Enable Resource Resolver Leak Detection: If you continue to face difficulties pinpointing the issue, consider enabling the Resource Resolver Leak Detection feature in OSGi. This can help identify where resource resolvers are not being closed. -> https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-16548

  5. Audit and Test: Perform a thorough audit of your application's use of the ResourceResolver API and create unit and integration tests to ensure resource resolvers are always closed. Testing in an environment that closely mirrors your live setup can help identify issues that only occur under specific conditions.
  6. Upgrade to AEM 6.5's latest Service Pack: If you find out that this exception is coming from the platform itself, please install the latest service pack, as most previous product problems are fixed and enhanced.