[PJUG Javamail] What causes "Too many open files" in Tomcat

Creyf, Jo Jo.Creyf at nike.com
Tue Nov 3 20:03:02 EST 2009


I've seen this issue before where an application running in Tomcat was
not explicitly closing network sockets and was leaving handles in a
CLOSE_WAIT state.

The application was grabbing a new IP port each time and left previously
used ports in limbo land.

Note that this was not a Tomcat issue but more of a coding issue.

The issue was resolved by explicitly closing and cleaning up network
sockets.

The ulimit setting tells the operating system that each running process
on the machine can have up to that number of handles (file handles and
network handles).  If the setting is 1024, then the Tomcat process can
have up to 1024 files and network ports open.  You'll get the "Too many
open files" if that number is reached and Tomcat tries to grab another
file or network handle.

 

The too many open files message may be confusing.  I think it should
actually read "Too many open handles".

Your stack trace is showing java.net.SocketException, which leads me to
think that you too may be dealing with some code that is leaving network
handles open.

 

You may want to run lsof and probably grep for "CLOSE_WAIT" or grep for
your Tomcat's process id and monitor the output for a while to see what
is eating up your resources.

 

Good luck!

Jo Creyf

 

 

From: javamail-bounces at pjug.org [mailto:javamail-bounces at pjug.org] On
Behalf Of Rob Tanner
Sent: Tuesday, November 03, 2009 4:01 PM
To: Chris Foster
Cc: Portland Java Users Group
Subject: Re: [PJUG Javamail] What causes "Too many open files" in Tomcat

 

I thought about that but the problem isn't system wide.  But thanks
because you've just reminded me that ulimit is shell specific although
the default of 1024 should certainly be sufficient.  I've modified the
catalina.sh start up script to set ulimit to 4096 (ulimit -n 4096).
That's definitely overkill and if ulimit was the problem, I shouldn't
see that error again.  I'll just need to keep an eye out.

Again thanks,

Rob


On 11/3/09 3:25 PM, "Chris Foster" <cjafoster at gmail.com> wrote:

Check your ulimit. Chances are the Linux (or unix) file limit is too
low.

- Chris

On Nov 3, 2009, at 2:53 PM, Rob Tanner <rtanner at linfield.edu> wrote:

Hi,

I'm getting messages like these in the catalina.out log:

java.net.SocketException: Too many open files
java.io.FileNotFoundException: /usr/dict/wordlist.pwd (Too many open
files)
java.io.FileNotFoundException:
/var/apache/apache-tomcat-5.5.23/webapps/AccountManager/WEB-INF/classes/
log4j.properties (Too many open files)
java.net.SocketException: Too many open files



And, of course, I have to stop and restart Tomcat to get it to work
again.  This is not a system error; it's only in Tomcat.  I did some
googling and found a suggestion with regard to Java arguments when
Tomcat starts up.  

These are the options I'm starting Tomcat with: '-XX:NewSize=128m
-XX:MaxNewSize=128m -XX:SurvivorRatio=8 -Xms256m -Xmx512m'

I've also gone through the most active apps and made sure that I was not
leaving any database or LDAP connections open.

Any ideas?

Thanks,
Rob



Rob Tanner
JAVA Developer
Linfield College, McMinnville Oregon



_______________________________________________
Web Site - http://www.pjug.org/ <http://www.pjug.org/> 
Javamail mailing list
Javamail at pjug.org
http://www.pjug.org/mailman/listinfo/javamail

 

________________________________

_______________________________________________
Web Site - http://www.pjug.org/
Javamail mailing list
Javamail at pjug.org
http://www.pjug.org/mailman/listinfo/javamail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pjug.org/pipermail/javamail/attachments/20091103/bbf8d2b1/attachment.html 


More information about the Javamail mailing list