Here\'s a straightforward Go http (tcp) connection test script
func main() {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *htt
HTTP/1.1 uses persistent connections by default:
A significant difference between HTTP/1.1 and earlier versions of HTTP is that persistent connections are the default behavior of any HTTP connection.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
The solution was to inform the server that the client wants to close the connection after the transaction is complete. This can be done by setting the Connection header,
req.Header.Set("Connection", "close") or by setting the Close property to true on the http.Request:
req.Close = true After doing that, the “too many open files” issue went away as the program was no longer keeping HTTP connections open and thus not using up file descriptors.
I solved this by adding req.Close = true and req.Header.Set("Connection", "close"). I think it's better than changing ulimit.
source: http://craigwickesser.com/2015/01/golang-http-to-many-open-files/