Wednesday, 28 July 2010

Increasing file handle limit in Ubuntu

I got the below error whilst trying to run my Grails application this morning:-

....
Caused by: java.io.IOException: java.io.IOException: error=24, Too many open files at java.lang.UNIXProcess.(UNIXProcess.java:148)
....

After a bit of digging around, it appears that some of the later versions of the Java JVM 1.6.+ are not closing unused file connections, which results in the default limit that is set for users in Ubuntu being hit and the above exception being thrown.

After searching the web I found the following solution.

To modify the limit for the current user session you can simply type the below into your bash terminal:-

$ulimit -n 2048

This will double the default value, but the changes will be lost upon restart of the machine.

To include a change in the system configuration, which will not be lost on restart, you will need to do the following:-

1. Edit limits.conf

$sudo gedit /etc/security/limits.conf

to include the line:

YourUser - nofile 51200

2. Update the common-session configuration

$sudo gedit /etc/pam.d/common-session

to include the line:

session required pam_limits.so

Logout and log back in again and that should solve it.

Type "$ulimit -n" into a terminal and you should now see your new limit has been set, if not try giving the machine a restart.

Happy hunting...

No comments: