Expand my Community achievements bar.

SOLVED

Unclosed resource resolver

Avatar

Level 3

I am dealing with unclosed resource resolver warnings and working on solutions to fix this. In the process I came across this article - https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-23761#

This article offers the following workaround:

tatvam_0-1761579423030.png

The solution seems to close the resource resolver from just one resource instead of "iterating" over the iterator.
For eg:

//workaround: close internal resource resolver(s)

Iterator< Resource> resources = result.getResources();
while (resources.hasNext()) {

Resource resource = resources.next();
resource.getResourceResolver().close();
}


Appreciate your suggestions!!

PS: Tried to use the "suggest an edit" option on that page and got a 404.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 10

 

hi @tatvam
Each hit.getResource().getResourceResolver() returns the same ResourceResolver instance (the leaking one). Closing a ResourceResolver multiple times would cause errors, so you only need to close it once to fix the leak.

 

The code here also correctly uses resourceResolver.getResource(hit.getPath()) (the resolver passed into the method) when collecting resources to return, rather than using hit.getResource() directly. This ensures you're working with resources from a resolver you control, not the one that's about to be closed (this is a defensive pattern to handle a QueryBuilder implementation bug).

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

 

hi @tatvam
Each hit.getResource().getResourceResolver() returns the same ResourceResolver instance (the leaking one). Closing a ResourceResolver multiple times would cause errors, so you only need to close it once to fix the leak.

 

The code here also correctly uses resourceResolver.getResource(hit.getPath()) (the resolver passed into the method) when collecting resources to return, rather than using hit.getResource() directly. This ensures you're working with resources from a resolver you control, not the one that's about to be closed (this is a defensive pattern to handle a QueryBuilder implementation bug).

 

Avatar

Level 3

Thanks for the response. I think adding this line

Each hit.getResource().getResourceResolver() returns the same ResourceResolver instance (the leaking one)


 to the KB article will be very helpful. Appreciate if someone could help.