The nexus.log file is full of "too many open files" exceptions, how can I fix this?

The Lucene search indexes maintained by Nexus can temporarily use 10-20 files per repository during re-index and search operations (this is a very rough approximation).

Nexus Professional will consume about 400 file handles on a clean start. So as the number of indexed repositories in a Nexus instance increases you may start to approach your system's default limits for open file handles. When you hit this limit you will see "too many open files" exceptions in the logs.

To recover from this you must first increase the limit, then repair the damage.

Checking the open file limit

*nix:

Determine the user id of the user running the Nexus process. Then execute the following:

# su - <nexus_userid>$ ulimit -Hn$ ulimit -Sn

Increasing the Open File Limit

Linux:

Default open file limit is usually 1024.

To increase this add this to /etc/security/limits.conf (where "nexus" is the UID of the user running Nexus).

This will take effect when the next login shell is executed. If you are running nexus via the "nexus" init.d script and you have RUN_AS_USER set then all you need to do is restart the nexus service. the script will login when it switches users.

Note 2: On Ubuntu, you also need to add the following line to /etc/pam.d/common-session:

session required pam_limits.so

Note: If you're using systemd to launch the server the above won't work. Instead, modify the configuration file to add a "LimitNOFILE" line:

Repairing the Damage

The most likely areas of damage after running out of file handles or filling up a disk are the Lucene and RDF indexes, databases, and the repository storage areas.

To fix the search indexes, schedule a "repair index" task against "all repositories. The are also Lucene indexes for the system feeds, these are stored in "sonatype-work/nexus/timeline. These will be fixed automatically at startup if Nexus detects they are corrupted.

In the storage area, Nexus may have created zero length files. This happens because a directory entry can still be created on a full disk. To find these, run the following in sonatype-work/nexus/storage:

find . -type f -size 0

Double check that the above worked correctly, and then to remove them run: