Sobes.tech
Junior — Middle

What will you do if your application crashes due to exhaustion of available file descriptors?

sobes.tech AI

Answer from AI

If an application crashes due to exhaustion of available file descriptors, the following steps should be taken:

  1. Check the current descriptor limits using the command ulimit -n (for Linux/Unix).
  2. Increase the open file limit for the process or user, for example, by changing settings in /etc/security/limits.conf or using ulimit -n <new_value>.
  3. Analyze the application code for descriptor leaks — ensure that all files, sockets, and other resources are properly closed after use.
  4. Use monitoring tools (e.g., lsof, strace) to identify open descriptors and their sources.

Example of checking and changing the limit:

ulimit -n          # show current limit
ulimit -n 65535    # set new limit for the session

It is important not only to increase the limit but also to eliminate the cause of descriptor leaks in the code.