I know there are a lot of these questions on SO but I cannot see anything that matches my specific situation.
I am running a .NET console application via Mono on Ubuntu. The app runs as a server and accepts connections via a TcpListener (TcpListener.AcceptTcpClient()). The problem I have is that after a while the program starts throwing 'Too many open files' exceptions.
I have increased the max file limit in Ubuntu in the two places that I am aware of:
- /etc/security/limits.conf
root soft nofile 240000
root hard nofile 320000
(The process in question runs as root)
- /etc/sysctl.conf
fs.file-max = 2000000
Both are set to ~200000.
If check the number of open file descriptions on the system it is only 996 even though it is throwing the errors.
I have the same program running on several Windows servers with many more connections and they never have this problem.
Any idea what could be causing this error?