Linux Tomcat max open files

First of all, I must say that Tomcat is one code that shouldn’t be never written. Troubleshooting is a bitch, it uses Java, and the official support is closing to zero.

I stumbled into a error (in a Debian / Ubuntu) where a Tomcat app writes into /var/log/tomcat7/catalina.date.log an error saying

java.net.SocketException: Too many open files"

The app itself also displayed a variety of errors, which basically said nothing.

Tried to hack the “/etc/security/limits.conf” -file – no help there

Tried to hack the “/etc/sysctl.conf” -files – no help there

Tried the “ulimit -n” -way – no help there

After this I contacted Tomcat official support, and the answer was that I should install the instance in a Windows Server -machine, and check, if the problem still extists. (!!!) The server itself had a variety of services, so that was out of the question. Must dig deeper.

After of hours of surfing I came across a known bug of of Tomcat: https://ubuntuforums.org/showthread.php?t=1583041

…and the resolution, you must hack the /etc/init.d/tomcat7 -file

Inserting lines:

ulimit Hn 16384
ulimit Sn 16384
into a file /etc/init.d/tomcat7 did the trick. I inserted the following:
[sourcecode]
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO

ulimit -Hn 16384
ulimit -Sn 16384

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=tomcat7

[/sourcecode]

From the above I inserted the two “ulimit…” lines, and voil’a, worked.
Before the change (and reboot) it was:
[sourcecode]
ps aux | grep tomcat
[/sourcecode]

[sourcecode]
cat /proc/<pid>/limits
Max open files            1024               1024                files
[/sourcecode]

And after the setting (and reboot) it was:[sourcecode language="csharp"]
Max open files            16384                16384                files
[/sourcecode]
I hope anyone doesn’t have to hack this error, and if does, this one will help.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *