To avoid this, you have to increase the number of open files in the configuration file of your Linux System. There are two limits. One is global (for all users) and one is a per-user limit (1024 by default).

Count File Descriptors in Use

Count Open File Handles

sudo lsof [-u user] | wc -l

Count File Descriptors in Kernel Memory

sudo sysctl fs.file-nr
# => The number of allocated file handles
# => The number of unused-but-allocated file handles
# => The system-wide maximum number of file handles

Raising the Global Limit

Edit /etc/sysctl.conf and add the following line:

fs.file-max = 65536

Apply the changes with:

sudo sysctl -p /etc/sysctl.conf

Raising the per-User Limit

On some systems, it is possible to use the ulimit -Hn 8192 and ulimit -Sn 4096 commands. However, most of the time this is forbidden and you will get an error such as: