Matomo Analytics

The "Too many open files (os error 24)" error in Ubuntu is an indication that a process is trying to open more files than the system limit allows. This can be due to your system's file descriptor limit being set too low for your needs. Here's a step-by-step guide to diagnose and fix this issue:

1. Check Current Limits

First, you need to understand your current limits. There are two types of limits you can check: the limit for the shell session and the global system limit.

- Shell Session Limit: Run ulimit -n to see the maximum number of open file descriptors for the current shell session.

- System-wide Limit: Check the system-wide limit by examining the contents of /proc/sys/fs/file-max with cat /proc/sys/fs/file-max.

2. Increase the Limit Temporarily

To temporarily increase the limit for your current shell session, you can use the ulimit command. For example, to set the limit to 4096, you can do:

ulimit -n 4096

3. Increase the Limit Permanently

To permanently increase the number of open files limit, you'll need to edit system configuration files:

- Edit Limits for Specific User: Edit /etc/security/limits.conf and add the following lines, replacing username with your actual username:

username soft nofile 4096
username hard nofile 10000

Here, soft is the limit that the user can increase up to the hard limit using ulimit without requiring root privileges.

- Edit System-wide Limits: For a global change, edit /etc/sysctl.conf and add:

fs.file-max = 100000

After editing /etc/sysctl.conf, apply the changes with sudo sysctl -p.

4. Verify the Changes

After making changes, either log out and log back in (for changes in /etc/security/limits.conf) or reboot your system (for changes in /etc/sysctl.conf). Then, verify that the changes have been applied:

- For user-specific limits, open a new terminal and run ulimit -n.

- For system-wide limits, check with cat /proc/sys/fs/file-max.

5. Adjusting Open File Limit for Systemd Services

If you're running a service that's managed by systemd and it's the one running into the "Too many open files" error, you might need to adjust limits for the service unit:

- Edit the service unit file (usually located in /etc/systemd/system/ or a similar directory). Add or modify the [Service] section to include:

  LimitNOFILE=10000

- After editing, reload systemd configuration with sudo systemctl daemon-reload and restart the service.

Troubleshooting

- If you continue to experience problems, ensure that your application or service is not leaking file descriptors by improperly handling file operations.

- Consider using tools like lsof to list open files and identify where the file descriptors are being consumed.

By following these steps, you should be able to resolve the "Too many open files (os error 24)" error on Ubuntu. If the problem persists, it might be worth investigating the specific applications you're running for potential bugs or misconfigurations that could be leading to excessive open file descriptors.

11 March 2024 (last updated 8 months ago)

6788 views

Written by Dennis

Dennis brings over 6 years of hands-on experience in server management, specializing in optimizing web services for scalability and security.

Back to Server


Start free trial