EMFILE 🐧 Linux

Too many open files (EMFILE)

The process hit its file-descriptor limit — sockets, files and pipes all count.

Seen on: Linux Node.js Java

Meaning

Each process has a soft limit (often 1024). Busy servers, file watchers and connection leaks exceed it. Node shows EMFILE: too many open files, Java java.io.IOException: Too many open files.

Common causes

  • Low default ulimit -n (1024)
  • Leaking file handles or sockets (not closed)
  • File watchers on huge trees (webpack/jest/nodemon watching node_modules)
  • High-concurrency servers

⚡ Quick fix

  1. Check usage: ls /proc/<pid>/fd | wc -l vs ulimit -n
  2. Raise the limit for the service (systemd LimitNOFILE)
  3. Fix leaks — close files/sockets, reuse HTTP agents
  4. Exclude node_modules from watchers

Detailed fix by platform

Linux

  1. Raise the limit for a systemd service:
    ini
    # sudo systemctl edit myapp
    [Service]
    LimitNOFILE=65535

Node.js

  1. Use graceful-fs for bulk file operations and limit concurrency (e.g. p-limit).

How to diagnose

  1. Count — Open FDs vs limit
  2. Kind — lsof -p <pid> — files or sockets?
  3. Leak — Does the count grow over time?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.