Too Many Open Files (per process)
Production Risk
File descriptor leaks will eventually crash the process. Monitor fd count in production with metrics.
The process has reached its per-process limit on open file descriptors (RLIMIT_NOFILE). The default soft limit is typically 1024 on Linux. This can indicate a file descriptor leak in the application.
- 1The application opens files or sockets without closing them (file descriptor leak).
- 2The default ulimit of 1024 is too low for the application workload.
- 3Many simultaneous client connections are being maintained without connection limits.
- 4Temp files or pipes are created in a loop without cleanup.
Opening more than 1024 file descriptors without closing old ones.
$ ulimit -n
1024
# After opening 1024 file descriptors:
open("/tmp/file1025", O_RDONLY) = -1 EMFILE (Too many open files)expected output
open: Too many open files EMFILE
Fix 1
Increase the file descriptor limit
WHEN When the application legitimately needs more than 1024 descriptors
# Per session ulimit -n 65536 # Permanent (add to /etc/security/limits.conf) # myuser soft nofile 65536 # myuser hard nofile 65536
Why this works
Raising RLIMIT_NOFILE allows the process to hold more open file descriptors simultaneously.
Fix 2
Find and fix file descriptor leaks
WHEN When the number of open descriptors grows over time
# Check how many fds the process has open ls /proc/$PID/fd | wc -l # List what they are ls -la /proc/$PID/fd
Why this works
Listing the open file descriptors for the process reveals which types are leaking.
Linux Programmer Manual errno(3)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev