Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http, x/net/netutil: Cannot Set TCP Connection Limitation for Go HTTP Server #36212
What version of Go are you using (
As far as I understand, your code makes it so that more than 20 connections can be accepted simultaneously. However, after some connections are accepted, more connections can be accepted, so
Do you think there's a bug somewhere, or is this a feature request?
All status of these 100 sockets are ESTABLISHED.
@dmitshur Thanks for your explanation. I think I need a feature that only 20 connections can be accepted simultaneously.
There are several reasons why you see a large connections number.
First, netstat shows structures for both inbound and outbound connections. For example, for two connections you will see:
One structure for the server, one for the client.
Secondly, netstat shows structures for connections in other states, for example TIME_WAIT:
In this case, we see only one living connection, but there are 5 rows.
Thirdly, there is a difference between the
This difference will be visible if you look at the number of open file descriptors for the application. Set the limit to 1 and send two requests simultaneously (yes, you need to set time.Sleep in the handler so that it does not end immediately):
We look at the number of connections, one for the listening socket, two for incoming connections:
But we see only one file descriptor associated with the connection on port 62086.
Only when the first connection finish, the application will make another accept call and process the second connection on port 62010:
With LimitListener you can adjust the number of file descriptors for the server, but you cannot adjust the number of ESTABLISHED connections for the system.
We can say that the system queues incoming connections and they are waiting for their
To summarize, let’s say: