IntermediateScenario
10 min

EMFILE: Too Many Open Files

LinuxLimitsReliability
Advertisement
Interview Question

A service starts failing with EMFILE errors. Describe how you identify the cause and fix it.

Key Points to Cover
  • Check ulimit/systemd limits and kernel fs.file-max
  • Use lsof to find FD leaks (sockets, files, inotify)
  • Audit connection pools and HTTP client reuse
  • Raise limits safely and patch leak in code
  • Add FD usage dashboards and alerts
Evaluation Rubric
Identifies FD pressure correctly30% weight
Finds source of FD leaks30% weight
Applies short/long-term fixes20% weight
Adds observability/limits20% weight
Hints
  • 💡In-flight HTTP clients may leak sockets.
Common Pitfalls to Avoid
  • ⚠️Only checking `ulimit` and not considering systemd's `LimitNOFILE` directive.
  • ⚠️Forgetting to check global system limits (`fs.file-max`) when individual process limits seem sufficient.
  • ⚠️Not using `lsof` effectively to filter or analyze the output for specific FD types (e.g., sockets).
  • ⚠️Focusing solely on code logic and neglecting external dependencies or libraries for FD leaks.
  • ⚠️Implementing a fix without understanding the root cause, leading to recurring issues.
Potential Follow-up Questions
  • How to tune systemd service limits?
  • What about ephemeral ports?
Advertisement