Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Resource Resolver Leak

Avatar

Avatar
Validate 1
Level 1
SagarVerliani
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
SagarVerliani
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
SagarVerliani
Level 1

15-06-2021

Hi All,

 

We are facing this warning message multiple times in our 6.5.6 AEM environment. 

 

11.01.2018 01:03:18.878 *INFO* [Apache Sling Resource Resolver Finalizer Thread] org.apache.sling.resourceresolver.impl.CommonResourceResolverFactoryImpl Unclosed ResourceResolver was created here
 
From version 6.3 Adobe had recommended this workaround Solution (url given below), I just want to know if this is still a known bug like do we have any update for this in recent Service Packs.
https://helpx.adobe.com/bg/experience-manager/kb/Unclosed-ResourceResolver-warnng-at-com-day-cq-sear...
 
Also we are getting this error even when there is no Querybuilder API being hit.
 
Thanks!
 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 50
Employee
markus_bulla_adobe
Employee

Likes

138 likes

Total Posts

121 posts

Correct Reply

59 solutions
Top badges earned
Affirm 50
Boost 100
Applaud 25
Affirm 25
Boost 50
View profile

Avatar
Affirm 50
Employee
markus_bulla_adobe
Employee

Likes

138 likes

Total Posts

121 posts

Correct Reply

59 solutions
Top badges earned
Affirm 50
Boost 100
Applaud 25
Affirm 25
Boost 50
View profile
markus_bulla_adobe
Employee

15-06-2021

Hi @SagarVerliani!

 

The INFO level log message that you have posted is a warning mechanism of AEM to bring resource resolvers to your attention that are not correctly handled (specifically: not closed properly). The source of that unclosed resource resolver can usually be spotted in the stack trace that follows. Please refer to the stack trace after "Unclosed ResourceResolver was created here:" in your log file to start your analysis of the root cause of the unclosed resource resolver.

 

While there have been issues with actual AEM product code not correctly handling and closing resource resolvers in the past (as mentioned in the KB article that you are referencing), I'm not aware of any know issues with latest versions of AEM. In my experience, most of these cases are somehow (directly or indirectly) caused by custom project code. If your analysis points to AEM product code as a source of the improper handling of a resource resolver, please create a support ticket so that our customer care and engineering teams can check.

 

How to handle resource resolvers correctly?

Please refer to the Sling API and this thread for more information on how to correctly handle (e. g. open and close) resource resolvers.

From the API documentation:

A Resource Resolver has a life cycle which begins with the creation of the Resource Resolver using any of the factory methods and ends with calling the close() method. It is very important to call the close() method once the resource resolver is not used any more to ensure any system resources are properly clean up.

From the thread (answer by @Feike_Visser1) :

Follow the rule "You open a resourceResovler / Session, You Close it". 

If this is not the case, leave it...

 

Also, @Jörg_Hoh covers this in his blog post on CQ development patterns (see "2nd pattern: Ownership: You open it — you close it.") and as mentioned by @Bhuwan_B he recommends to leverage the try-with-resource pattern in another article.

 

Hope that helps!

Answers (2)

Answers (2)

Avatar

Avatar
Give Back 5
Level 6
Bhuwan_B
Level 6

Likes

132 likes

Total Posts

122 posts

Correct Reply

48 solutions
Top badges earned
Give Back 5
Boost 100
Give Back 3
Affirm 25
Establish
View profile

Avatar
Give Back 5
Level 6
Bhuwan_B
Level 6

Likes

132 likes

Total Posts

122 posts

Correct Reply

48 solutions
Top badges earned
Give Back 5
Boost 100
Give Back 3
Affirm 25
Establish
View profile
Bhuwan_B
Level 6

15-06-2021

@SagarVerliani Please check below URL:

https://cqdump.joerghoh.de/2018/11/14/try-with-resource-or-i-will-never-forget-to-close-a-resource-r...

In Java 7 the idiom “try-with-resource”  has been introduced in the java world. It helps to never forget to close a resource. And since Sling9 (roughly 2016) the ResourceResolver interface implements the AutoCloseable marker interface, so the try-with-resource idiom can be used.

That means, that you can and should use this approach:

try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(…)) {
// do something with the resolver
// no need to close it explicitly, it's closed automatically
}

 

Avatar

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct Reply

44 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct Reply

44 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 7

15-06-2021

Hi @SagarVerliani ,

 

If you use Try-with-Resource for ResoureResolver then you will not get such warnings, else you need to close that in finally block.

 

try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(…)) {
// ResourceResolver will be closed automatically ater this
}