Skip to content

Troubleshoot Too Many Open Files in a Linux Service

Admin
November 20, 2026
5 min read
Intermediate
💻 Target OS: Ubuntu 26.04 LTS / RHEL 10

Before you begin

  • Applies to:Linux hosts running the affected service under systemd.
  • Where to start:Open a shell on the host where the error appeared.
  • What you need:Record the exact error and its time. Have access to the service journal and the affected worker under /proc. Use the real unit name and worker PID. The main PID may belong to a supervisor.
Guide tools
Guide tools
0/0 Steps (0%)

Troubleshooting Steps

01

Identify the failing process and error

Start here

Check the service journal. Where the application reports errno, EMFILE points to a per-process limit, while ENFILE points to a system-wide file table limit. Match the timestamp and worker to the request that failed.

Terminal window
sudo journalctl -u example.service --since '30 minutes ago' --no-pager
systemctl show example.service -p MainPID -p LimitNOFILE -p LimitNOFILESoft
02

Inspect the running worker's effective limits

The configured unit limit can differ from a process that changes its own limits. Compare the soft and hard Max open files values. A shell’s ulimit describes that shell and its descendants.

What you should see · The running worker has a soft and hard Max open files value in its process limits.

If you see something else · If the PID no longer exists, get the current worker PID before measuring. If it is still running, compare its descriptor count against the soft limit in Step 3 before changing it.

Terminal window
pid=1234
sudo grep -F 'Max open files' "/proc/$pid/limits"
03

Sample descriptors under normal load

Count the current descriptors and compare several samples from the same worker. A worker can exit or reuse descriptors while you inspect it. Use lsof if available to distinguish files, sockets, or other descriptor types. Inspect FD entries rather than counting all lsof rows.

Terminal window
pid=1234
(set -o pipefail; sudo ls -1 -- "/proc/$pid/fd" | wc -l)
sudo lsof -nP -p "$pid"
04

Separate system-wide pressure from one worker

When several unrelated services report ENFILE, review allocated kernel file handles and the configured maximum. file-nr and file-max describe system-wide state. Compare the observed numbers and kernel logs during the failure rather than inferring saturation from one process count.

Terminal window
cat /proc/sys/fs/file-nr /proc/sys/fs/file-max
05

Choose a correction based on growth

If descriptors grow with no corresponding workload growth, investigate application or connection cleanup with its owner. If normal workload reaches a justified process limit, select a vendor-supported soft and hard limit, record the existing setting, and use an approved service-specific drop-in. A running process needs an approved restart to inherit the revised setting.

06

Verify the worker and the original workload

Verify

Recheck the replacement worker’s effective values, descriptor trend, and job results during comparable load. If a change causes regressions, restore the prior drop-in, reload systemd, and restart through the agreed maintenance workflow.

Decide What to Do Next

FindingNext action
One worker approaches its soft limitCompare descriptor types and behavior under stable load.
Several services report ENFILECompare the system-wide file table with kernel messages.

References

Comments