net/http: Golang socket: too many open files



Ulimits are Linux and Unix features that allows limiting how much resources a user uses, such as processes, CPU time, and various types of memory. You can view your shell’s current ulimits with the command ulimit -a.

“Too many open files” errors happen when a process needs to open more files than it is allowed by the operating system. This number is controlled by the maximum number of file descriptors the process has.


Temporal solution:

The number of file descriptors for the current process can be shown with the following commands:


To temporal change, the number of file descriptors, execute the command ulimit -n


To know the limits for the current Process:

The current limits set for the process that reach that limits can be verified in the /proc file system. example the limits for Postgres:



To change permanent.

Change or add these lines in /etc/security/limits.conf


* gouser is the user which run the golang server

Add or change this line to /etc/sysctl.conf


And execute this command:



Add to the end of the file /etc/profile:

Open a new terminal and execute: