The error means a process hit its file descriptor limit (ulimit -n, often 1024 by default). Check how many descriptors the process uses with ls /proc/PID/fd | wc -l and its limit in /proc/PID/limits. Raise it with LimitNOFILE= in the systemd unit — limits.conf does not apply to systemd services — and check for a descriptor leak if usage keeps climbing.
Symptoms
- Logs show “Too many open files” or EMFILE
- Web servers or databases refuse new connections
- Errors appear under load and clear after a restart
How to diagnose it
Check the process limit and usage
Compare the open count with the Max open files soft limit.
cat /proc/PID/limits | grep "open files" sudo ls /proc/PID/fd | wc -lSee what the descriptors are
Mostly sockets means connections; mostly the same file means a leak.
sudo lsof -p PID | awk '{print $5}' | sort | uniq -c | sort -rnCheck the system-wide limit
The first number is allocated handles; the third is the kernel maximum.
cat /proc/sys/fs/file-nr cat /proc/sys/fs/file-max
Common causes and fixes
Service limit too low for its connection count
Raise it with a systemd drop-in.
sudo systemctl edit SERVICE
# add:
[Service]
LimitNOFILE=65535
# then
sudo systemctl restart SERVICEApplication leaks file descriptors
If the count rises steadily without more traffic, the app is not closing files or sockets. Fix the code; raising limits only delays the failure.
Limit set in limits.conf but the process runs under systemd
/etc/security/limits.conf applies to login sessions (PAM), not services. Use LimitNOFILE in the unit.
nginx worker limit
Set worker_rlimit_nofile in nginx.conf and raise worker_connections to match.
Prevent it happening again
- Watch open file descriptor counts in Statance’s server history to spot steady growth.
- Set LimitNOFILE explicitly in units for web servers, databases and proxies.
Set it up: Linux monitoring.
FAQ
How do I check the open file limit in Linux?
ulimit -n shows it for your shell. For a running process, read /proc/PID/limits.
Why did changing limits.conf not work?
systemd services ignore limits.conf. Set LimitNOFILE in the service unit or a drop-in.
Related guides
Get alerted before this becomes an outage.
Install the agent in one line. Statance watches CPU, memory, disk and services, and its AI assistant helps find the cause.