Hostxpeed
Login Get Started →
Troubleshooting

Fix "Too Many Open Files" Error

5 min read
28 views
Jun 10, 2026

Understanding the Error

Process has exceeded file descriptor limit.

Too many open files
Cannot open file: ...

Check Current Limits

# Process limit
ulimit -n

# System-wide limit
cat /proc/sys/fs/file-max

# Current usage
lsof | wc -l

Fix 1: Increase Soft/Hard Limits per User

Edit /etc/security/limits.conf:

username soft nofile 65535
username hard nofile 65535
* soft nofile 65535   # All users
* hard nofile 65535

Fix 2: For Systemd Services

Edit service file:

sudo systemctl edit servicename

# Add:
[Service]
LimitNOFILE=65535

Then restart:

sudo systemctl daemon-reload
sudo systemctl restart servicename

Fix 3: Increase System-Wide Limit

echo "fs.file-max = 2097152" >> /etc/sysctl.conf
sudo sysctl -p

Fix 4: Find What's Leaking File Descriptors

# For specific process
lsof -p PID | wc -l
lsof -p PID | head -50

# Find process with most open files
lsof -n | awk '{print $2}' | sort | uniq -c | sort -nr | head -10

Fix 5: Application-Level Fix

Check for:

  • Not closing database connections
  • Not closing file handles
  • Log files rotation issues

Restart application to clear descriptors.

For MariaDB/MySQL

# In my.cnf
open_files_limit = 100000
table_open_cache = 4000

Was this article helpful?