Repository unavailable errors occur during scheduled importer jobs in AEM as a Cloud Service
Adobe Experience Manager (AEM) as a Cloud Service scheduled importer jobs may intermittently fail with org.apache.sling.api.resource.LoginException: Repository unavailable when unclosed ResourceResolver instances cause resource exhaustion or high repository load temporarily prevents new sessions from being created. To resolve the issue, ensure that ResourceResolver instances are closed promptly, review logs and job load, verify service-user permissions, and monitor subsequent job runs.
Description description
Environment
Adobe Experience Manager as a Cloud Service (AEMaaCS), all versions
Issue/Symptoms
- Scheduled custom importer jobs intermittently report: org.apache.sling.api.resource.LoginException: Repository unavailable
- Errors may indicate that the
ResourceResolveris null or that service-user login failed for a specific path. - Only some records in a job run may fail while others complete successfully.
- The issue is more likely under higher load.
- The issue may be reproducible in lower environments such as DEV or QA.
Root cause
The error is usually caused by resource exhaustion from unclosed ResourceResolver instances in custom code or by high repository load that temporarily prevents new sessions from being created.
Resolution resolution
Follow the steps below to resolve the issue:
- Review the custom importer code and ensure that every
ResourceResolverinstance obtained is closed after use. Avoid keepingResourceResolverinstances open for extended periods. - Refactor the code so that
ResourceResolverinstances are created and closed as close as possible to their usage scope, for example, within a try-with-resources block orfinallyblock. - Enable DEBUG logging for
org.apache.sling.jcr.resourceand the custom service packages to monitorResourceResolverlifecycle events and identify potential leaks. - Check
error.logandaudit.logfor warnings about unclosedResourceResolverinstances or resource exhaustion. - Temporarily reduce the number of records processed per job run and monitor whether the error continues. If the error disappears under lower load, this suggests resource exhaustion or contention.
- Ensure that other heavy jobs, schedulers, or repository maintenance tasks don’t overlap with the importer job schedule.
- Verify that the service user used for
ResourceResolveracquisition has the correct permissions and is properly mapped in the repository. - After making the code changes, monitor subsequent job runs and confirm that the error no longer occurs.