The Hidden Culprit: How File Descriptor Limits Trigger Web Server Failures
A Linux web service can fail when it exhausts its available file descriptors, but the resulting symptom is not always HTTP 500 and an HTTP 500 does not prove a descriptor limit was reached. The useful troubleshooting task is to establish whether the process received EMFILE (“too many open files”) or a related resource error, identify what is consuming descriptors, and choose between a leak fix, capacity adjustment, or upstream incident response.
Look for application or server logs with EMFILE, Too many open files, failed accept() calls, database connection failures, or inability to open new log files. Pair those messages with service restart history and request load. Failures can occur in an application runtime, reverse proxy, database client, or another process in the request path; each has its own descriptor consumption and effective resource limits.
An HTTP 500 may also come from an exception, broken template, exhausted database pool, or misconfiguration. Use the error evidence to narrow the cause rather than increasing every limit in response to any server error.
On a controlled Linux host, inspect the PID of the relevant service and its current descriptor usage. Examples include the process’s /proc/<pid>/fd/ directory and limits recorded in /proc/<pid>/limits; exact visibility requires suitable permissions. The ulimit -n value in your current terminal may differ from the limit inherited by a systemd service, container process, or process supervisor.
Count descriptors by type if possible: network sockets, pipes, files, event descriptors and deleted-but-still-open files may each point to a different leak or workload behavior. Note that the count itself does not reveal whether those descriptors should exist; compare against a healthy baseline.
| Pattern | Hypothesis to test | Next evidence |
|---|---|---|
| Count rises with traffic then falls | Expected concurrency pressure | Connections per worker and response latency |
| Count climbs monotonically after requests stop | Possible descriptor or connection leak | Stacks, unclosed files or client objects |
| Only one service fails while host is quiet | Service-specific limit/configuration | Per-process limit and logs |
| Hostwide allocation errors across services | System-wide pressure or different kernel resource | System metrics and kernel messages |
A leak fix can prevent the fault recurring; merely raising the ceiling can postpone the same failure and increase collateral resource usage.
If evidence shows normal peak concurrency and a legitimately undersized per-process limit, adjust it through the responsible supervisor or deployment configuration, not just a temporary interactive shell. Validate the new effective value after restart and test under representative load. If the service leaks descriptors, fix the lifecycle and add a regression test that performs many connections or file operations and returns to baseline.
Record the previous value and deployment revision for rollback. Check memory and connection limits because raising the descriptor ceiling without increasing other capacity may simply move the bottleneck.
A clean local health check is not proof of success if an upstream proxy is still failing or a database connection pool remains exhausted. Run one approved end-to-end request, inspect latency and status, and watch descriptor usage over a subsequent observation interval. Document which component was responsible and the evidence that the mitigation worked.
File-descriptor exhaustion is a diagnosable failure mode, not a universal web-server explanation. Prove the resource error, identify its source, and validate the smallest durable correction.