CodePark/ questions / I/O models, file descriptors & syscalls
START PRACTICINGPRACTICE
Backend question · OS, networking & Linux › I/O models, file descriptors & syscalls

Under load, a Node service starts failing with Error: EMFILE: too many open files. Which limit has it hit?

The per-process limit on open file descriptors (RLIMIT_NOFILE, shown by ulimit -n)

EMFILE means the process has hit its limit on open file descriptors. A file descriptor is a number the kernel gives a process for each open file, socket or pipe. The limit is the RLIMIT_NOFILE soft limit, and ulimit -n shows it. Every socket, file and pipe counts toward it.

The other options give different errors:

• "The disk has run out of inodes" gives
ENOSPC.
• "The system has run out of ephemeral ports" gives
EADDRNOTAVAIL.

Fix descriptor leaks first. If the load is real and expected, then raise the limit, for example with
LimitNOFILE= in a systemd unit.