ENFILE
Linux / POSIXERRORCommonFile SystemHIGH confidence

File Table Overflow

Production Risk

HIGH — ENFILE affects all processes on the system, not just the offending one.

What this means

ENFILE (errno 23) is returned when the system-wide limit on open file descriptors has been reached. Unlike EMFILE (which is per-process), ENFILE means no more files can be opened by any process on the system.

Why it happens
  1. 1System-wide open file limit (fs.file-max) exhausted
  2. 2A runaway process opening millions of file descriptors is affecting the whole system
  3. 3Very high concurrency on a server with a low file-max setting
How to reproduce

Server under heavy load exhausts the system-wide file descriptor table.

trigger — this will error
trigger — this will error
# Check current system-wide usage vs limit:
cat /proc/sys/fs/file-nr
# Output: open_fds  unused  max_fds

expected output

open: Too many open files in system (ENFILE)

Fix

Increase the system-wide file descriptor limit

WHEN When the system-wide limit is genuinely too low for the workload

Increase the system-wide file descriptor limit
# Temporary:
sysctl -w fs.file-max=2097152

# Permanent (add to /etc/sysctl.conf):
fs.file-max = 2097152

Why this works

fs.file-max controls the maximum number of file descriptors that can be open system-wide. Increase proportionally to available RAM.

What not to do

Confuse ENFILE with EMFILE

ENFILE is system-wide; EMFILE is per-process. The fix differs: ENFILE needs sysctl; EMFILE needs ulimit or per-process limits.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors