Question: we are having problem with Kafka. sometimes Suddenly, without warning we go out of Synchronization and start to get exceptions when emitting events.

the exception we are getting is 

```
java.io.IOException: Too many open files

```

it seems this is a generic exception thrown by Kafka in many cases. We investigated it a little and we think the root cause is when trying to emit events to some topic, it fails because kafka dosen't have a leader partition for this topic

can someone help ?

Answer: 
I assume that you are on Linux. If that is the case, then what's happening is that you are running out of open file descriptors. The real question is why this is happening.

Linux by default generally keeps this number fairly low. You can check the actual value via ulimit:

```
ulimit -a | grep "open files"

```

You can then set that value via, again ulimit:

```
sudo ulimit -n 4096

```

That said, unless the Kafka host in question has lots of topics / partitions it is unusual to hit that limit. What's probably happening is that some other process is keeping files or connections open. In order to figure out which process you're going to have to do some detective work with lsof.
One of the case this happens is that when you have big partition number, because each partition maps to a directory in file system in broker that consist of two files. one of them is for the index and another is for data. broker opens both files. so more partition numbers there is more open files. as Doomy said you can increase the open files in linux but this config is not permanent and when you close the session this config will disappear. and in next loggin if you check with this command 

```
ulimit -a | grep "open files"

```

you can see the older number. but with this config you can make it permanent:

open this file:

```
sudo nano /etc/pam.d/common-session

```

and add this line:

```
session required pam_limits.so

```

after that you can set the limit in limits.config as this:

```
sudo nano /etc/security/limits.conf

```

and then you can set limit in this file forexample

```
* soft nofile 80000

```

or any hard config. after that close your session and check again the limit of open files