Thursday, January 7, 2010 Too many open files

There is limitation on how any open file handles (this includes sockets too) OS can support. If this limit is reached, you get above exception. If you are on ∗ nix OS, this can be easily increased.

Open /etc/security/limits.conf

I am on Ubuntu so for me I just execute following command from command line

sudo gedit /etc/security/limits.conf

and add following two lines

∗ soft nofile 3072
∗ hard nofile 3072

Save and Close the file. I don't know how to load these settings from command prompt but rebooting did the trick. To make sure these changes are done execute

ulimit -n

If you know how to do it on windows please add comment.



Anonymous said...

For Windows:

1. Log in to Windows using an account with Windows administrator privileges, or use the default “sa” login.

2. Start the regedt32 utility from the run prompt.

3. Select the Registry window HKEY_LOCAL MACHINE.

4. Open the Registry key HKEY_LOCAL_MACHINE\SYSTEM\ CurrentControlSet\Services\Tcpip\Parameters.

5. If the TcpNumConnections value exists, go to step 6.

If the value does not exist, add and configure it by completing the steps under “To add a TcpNumConnections value.”

6. Double-click the value.

7. In the DWORD Editor dialog box, select the Decimal option.

8. In the Data text box, enter the maximum number of connections to support.

9. Click OK to return to the Registry key dialog box.

10. If you have completed your tasks in regedt32, select Exit from the Registry menu to quit regedt32 and then restart your computer.

Adding a TcpNumConnections value in the registry editor:

1. Complete the Add Value dialog box as follows:

2. Value Name – TcpNumConnections

3. Data Type – select REG_DWORD from the drop-down list.

4. Click OK.

Complete the DWORD Editor dialog box as follows:

1. Data – enter the maximum number of TCP connections for the computer.

2. Radix – select the Decimal option button.

3. Click OK.

4. The utility adds the new value to the Registry key.

If you have completed your tasks in regedt32:

Choose Exit from the Registry menu to quit regedt32.

Restart your computer.

Hope this helps

Prabhat Jha said...

What you have to do on windows compared to that on Linux is like launching a space ship. ;-)

amit.bhayani said...

Thanks Aayush for such detailed explanation! Lol Prabhat you are right this is no less then launching Sapce Ship compared to linux.

vik said...

Hi Amit, I am recruiter from Rampgreen Technologies Delhi, we are a software product based company working on CRM and telephony software products, please let me know if you would like to work with us.
I will be happy to share more details with you, please let me know ur can email me at

Sunil said...

Hi Amit,
We are using jboss-4.2.3.GA, I am getting Socket accept failed Too many open files
at Method)
2012-01-31 11:30:01,274 ERROR []

Error Frequently an it is filling my jBosss log to 80 Gb .....

I have increased ulimit to 4096.

still it is not helping me.

could you Please help me on this.