EMFILE (errno 24)
errno 24
Too many open files
Also searched as: Too many open files, errno 24, EMFILE: too many open files
What it means
EMFILE, 'Too many open files' (errno 24), means one process has reached its limit of open file descriptors. Every socket, file and pipe counts. Busy servers, file watchers and leaking code hit it; the limit is per process (ENFILE is the system-wide equivalent).
Applies to: Linux, macOS (BSD errno), WSL, Docker containers
How to fix EMFILE (errno 24)
- Check the current limit with 'ulimit -n' and the process usage with 'ls /proc/<pid>/fd | wc -l'
- Find what is open with 'lsof -p <pid> | awk "{print \$5}" | sort | uniq -c' to spot a leak (thousands of sockets or the same file)
- Raise the shell limit for the session with 'ulimit -n 65535' (up to the hard limit)
- For systemd services, set 'LimitNOFILE=65535' in the unit's [Service] section, then 'systemctl daemon-reload' and restart
- For login sessions, set nofile limits in /etc/security/limits.conf
- Fix leaks in code: close files and sockets in finally/with blocks, and reuse HTTP connections with a pool
- On macOS, check 'launchctl limit maxfiles' and raise 'ulimit -n' in the shell
Why it happens
Each process has an RLIMIT_NOFILE soft limit, often 1024 by default. High concurrency, file watchers on large trees, and descriptor leaks push processes past it.
FAQ
What is the difference between EMFILE and ENFILE?
EMFILE is the per-process limit; ENFILE means the whole system's file table is full.
Why does raising ulimit not help my service?
Services started by systemd ignore your shell's ulimit. Set LimitNOFILE in the unit file.
Related errors
Source: Linux kernel errno.h · fixes written and reviewed by the editors (see our editorial policy)
Last updated: