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
- Reuse connections with a shared HTTP agent or client and keep-alive.
- Close files and sockets in finally blocks, and check for leaks with lsof -p PID | wc -l.
- Raise the limit: ulimit -n 65535, or LimitNOFILE= in the systemd unit.
Got a different message? Paste it into the error explainer.
Related errors
- curl: (3) URL using bad/illegal format or missing URL · curl could not parse the URL
- curl: (77) error setting certificate verify locations · curl can't read its CA certificate bundle
- unexpected eof while reading · The peer closed the connection without a TLS close
- Error: write EPIPE · Wrote to a connection the other side had closed
- TypeError: fetch failed · Node.js fetch failed below HTTP
- Error: listen EADDRINUSE: address already in use · Another process is already using the port
- unable to get local issuer certificate · The client can't find the certificate's issuer
- unable to verify the first certificate · The intermediate certificate is missing
- certificate has expired · The server certificate has expired
- self signed certificate in certificate chain · The chain ends in an untrusted root
- wrong version number · TLS spoken to something that isn't TLS
- curl: (6) Could not resolve host · The hostname doesn't resolve