Error: Too many open files

Issue

The log files contains the error, "Too many files," and AEM doesn't respond.

Solution

Increase the maximum number of open files configuration.

Certain AEM operations require the system to have more open files configured. For example, reindexing the lucene index can require you to increase the maximum open file settings.

Increase the open file limit for the AEM shell session

Check the user's limit for maximum open files, and then run the following as the same user that AEM process runs as:

ulimit -Sn ulimit -Hn

When using the default start script of AEM/CQ, do the following to increase the limit:

Open crx-quickstart/bin/start for editing

Add the variable CQ_MAX_OPEN_FILES to the top of the script:

CQ_MAX_OPEN_FILES=8192 export CQ_MAX_OPEN_FILES

If you see the error "-bash: ulimit: open files: cannot modify limit: Operation not permitted" when starting AEM, then the configuration above doesn't work.

Instead, it's necessary to increase the limit in /etc/security/limits.conf. See below for details on how to reconfigure the user limit.

If you are using a third-party application server such as JBoss or Websphere, follow the sections below and verify with the vendor's documentation.

Märkus.

If none of the configurations in this article solve the problem, then see what files are open using the command lsof -p. (-p is the process id of the problematic process.) It could be that your application is leaving file handles open. If you see that the handles are being held mostly by AEM and not your application, then contact support.

Increase the user's limits

To change the maximum number of open files for non-root users, change the file /etc/security/limits.conf. You can set the limit on a per-user basis:

crx_process_username soft nofile 8092

crx_process_username hard nofile 20000

Märkus.

This configuration doesn't take effect until the next time the user logs in.

Increase the system limit

Sometimes, the user limit is high enough, but the system itself has hit its maximum number of files. Run the following as su/root user:

Check the max open file setting on the operating system (if it is below 20000, then it makes sense to increase this setting).

cat /proc/sys/fs/file-max

Add this line to /etc/sysctl.conf to increase the system open file maximum value:

fs.file-max = 300000

Run this command:

sysctl -p

Verify that the new value is displayed when you run this command:

cat /proc/sys/fs/file-max

Märkus.

This configuration doesn't take effect until the next time the user logs in.

Additional information

This error occurs when the system or user is using its maximum number file handles.

Shell script that you can use to monitor the open file usage. Use this script only if the "too many open files" error persists even after you increase the maximum. Or, you can use it if you suspect that CRX or your application is leaving file handles open. Before using the script, configure the following variables: JAVA_HOME, QUICKSTART_PATH, OUTPUT_DIR, USER, MAX_FILES_THRESHOLD. To use the script, configure it as a cron job.