Too many open files — EMFILE error on process
EMFILE: Too many open files error in application logs
Focused incident mode — strips away everything but this runbook.
Symptoms
- EMFILE: Too many open files error in application logs
- accept() or open() calls fail
- Connection refused or dropped connections under load
EMFILE is a common failure under load. The default ulimit of 1024 is too low for any network-facing service. Always set this in the service unit file, not just in the shell.
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
Current open file descriptor count
ls /proc/<PID>/fd | wc -lProcess ulimit for open files
cat /proc/<PID>/limits | grep 'open files'
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- ulimit -n shows 1024 (default) for the service
- FD count is at the limit
Confirm before fixing
cat /proc/<PID>/limits | grep 'open files'Check the hard and soft limits
Fix
ulimit -n 65535Raise the open files limit (set in the service unit file or /etc/security/limits.conf)
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
ls /proc/<PID>/fd | wc -lCount current open FDs for the failing process
cat /proc/<PID>/limits | grep 'open files'Check the ulimit for open files
lsof -p <PID> | wc -lDetailed count of open files
ulimit -n 65535 && systemctl restart <service>Raise the limit and restart the service
Prevention
- Set LimitNOFILE=65535 or higher in systemd unit files for all network services.
- Alert on FD usage exceeding 80% of the process limit.
- Audit applications for FD leaks by monitoring lsof count over time.
- Set fs.file-max to a high value (2097152+) at boot via sysctl.conf.
Related runbooks
Same stack, same failure family — worth a skim.
Cannot assign requested address errors when connecting out
df shows full disk but du shows less total usage
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.