Debugging the "Too many files open" issue

James Raitsev picture James Raitsev · Apr 11, 2013 · Viewed 9.1k times · Source

The application i am working on suddenly crashed with

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

As i understand the issue it means that files are opened but not closed.

Stacktrace of course happens after the fact and can only help understand before what event error occurred.

What would be an intelligent way to search your code base to find this issue which only seems to occur when app is under high stress load.

Answer

BlackJoker picture BlackJoker · Apr 11, 2013
  1. use lsof -p pid to check what cause leak of file references;

  2. use ulimit -n to see the limit of opened file references of a single process;

  3. check any IO resources in your project,are they released in time?,Note that,File,Process,Socket(and Http connections) are all IO resources.

  4. sometimes, too many threads will cause this problem too.