'Apache tomcat "Too many open files" issue - How to check open files at an earlier point in time

We are getting below error in an application running on linux VM deployed on apache tomcat -

08-Feb-2022 01:27:10.732 SEVERE [http-nio-8080-Acceptor-0] org.apache.tomcat.util.net.NioEndpoint$Acceptor.run Socket accept failed
       java.io.IOException: Too many open files
           at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
           at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:421)
           at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:249)
           at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:482)
           at java.lang.Thread.run(Thread.java:748)

When this issue happened, the support team restarted the server to fix the issue. So no further information like using 'lsof' command to check the actual number of files/socketconnections open at that point of time were captured.

Is there any way to check historically what were the total no of files open or which were those connections open at an earlier point of time causing this issue?

Application is using postgresql DB and connection pooling.

Regards
Jacob



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source