Skip to content
MtrXTools

Error: EMFILE: too many open files

The process ran out of file descriptors

Seen in Node.js, Go (accept: too many open files), Python (Errno 24), nginx

The process hit its limit on open file descriptors, and every socket and file counts towards it.

Common causes

  • Opening a new connection per request without keep-alive or connection reuse.
  • Sockets or files that are never closed (a leak).
  • A low ulimit -n, often 1024, for a busy server or a file watcher on a large project.

How to fix it

  1. Reuse connections with a shared HTTP agent or client and keep-alive.
  2. Close files and sockets in finally blocks, and check for leaks with lsof -p PID | wc -l.
  3. Raise the limit: ulimit -n 65535, or LimitNOFILE= in the systemd unit.

Got a different message? Paste it into the error explainer.

Related errors

All 34 Command line & code errors