How to prevent a 'Too many open files' error

If you are seeing an error ‘Too many open files‘ then you may need to increase the number of file handles that the process running Tomcat is allowed to open.

The file /proc/sys/fs/file-max contains the max number of open files allowed at a system level. Change this value if necessary, for example by adding a line like the following to /etc/sysctl.conf:

fs.file-max = 65536

Most likely, it‘s a max-files per process problem (the default is 1024).
ulimit -Sn and ulimit -Hn shows you the max soft/hard open files allowed for the current user.
The best way to set it system-wide seems to be using the
/etc/security/limits.conf file e.g. add these two lines to the end of
the file:

* soft nofile 16384
* hard nofile 16384

It‘s a good idea to replace the "*" with specific users, or groups and set the number to whatever you deem appropriate. As long as pam is in use, and the "pam_limits" module is being used, this should then change the limit on new logins (assuming something in the login process doesn‘t override it afterwards). The ulimit() limits are inherited by child processes (unless they further restrict themselves by calling ulimit() again) - only root can raise the limits.

You can up it manually using ulimit -Sn <number> && ulimit -Hn <number> - you will need root privileges to do this.

Sometimes editing /etc/security/limits.conf does not affect the Tomcat process. An alternative is to add 'ulimit -n 16384' to /etc/default/tomcat6. You can check the limits that are currently in effect with 'cat /proc/<tomcat-pid>/limits'.

Was this article helpful?

Yes No

Thanks for your feedback!

Stew, Professional Services

“With so many settings available, and such a flexible system, do not hesitate to get in touch with one of our knowledgeable consultants to help you configure your Asset Bank.” Stewart, Professional Services