diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go index 6bfdb9e41..8e9b041dc 100644 --- a/pkg/tcpip/adapters/gonet/gonet.go +++ b/pkg/tcpip/adapters/gonet/gonet.go @@ -64,6 +64,14 @@ func NewTCPListener(s *stack.Stack, wq *waiter.Queue, ep tcpip.Endpoint) *TCPLis } } +// maxListenBacklog is set to be reasonably high for most uses of gonet. Go net +// package uses the value in /proc/sys/net/core/somaxconn file in Linux as the +// default listen backlog. The value below matches the default in common linux +// distros. +// +// See: https://cs.opensource.google/go/go/+/refs/tags/go1.18.1:src/net/sock_linux.go;drc=refs%2Ftags%2Fgo1.18.1;l=66 +const maxListenBacklog = 4096 + // ListenTCP creates a new TCPListener. func ListenTCP(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*TCPListener, error) { // Create a TCP endpoint, bind it, then start listening. @@ -83,7 +91,7 @@ func ListenTCP(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProt } } - if err := ep.Listen(10); err != nil { + if err := ep.Listen(maxListenBacklog); err != nil { ep.Close() return nil, &net.OpError{ Op: "listen",