Our java application is throwing "Too many open files" issue after running for a long duration. Upon debugging the issue, it's seen that there are so many fds open as per lsof output.
# lsof -p pid | grep "pipe" | wc -l
698962
# lsof -p pid | grep "anon_inode" | wc -l
349481
--------------Few lsof data-----------
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 23994 app 464u 0000 0,9 0 3042 anon_inode
java 23994 app 465u 0000 0,9 0 3042 anon_inode
java 23994 app 466r FIFO 0,8 0t0 962495977 pipe
java 23994 app 467w FIFO 0,8 0t0 962495977 pipe
java 23994 app 468r FIFO 0,8 0t0 963589016 pipe
java 23994 app 469w FIFO 0,8 0t0 963589016 pipe
java 23994 app 470u 0000 0,9 0 3042 anon_inode
java 23994 app 471u 0000 0,9 0 3042 anon_inode
How to find to the root reason for many open FDs of type FIFO and 0000.
There are not many file read/writes happening in our application. There so many TCP messages read from stream using apache mina framework which internally uses Nio.
These are my questions
The most likely thing is that you are opening resources and then not properly closing them. Make sure you use appropriate methods such as try-with-resources or try-finally blocks to tidy up.
To find the problem you should route all your IO through a class and then keep track of open and close, possibly even remembering the stack trace. You can then query that and see where you are leaking resources.