Bump default gonet.ListenTCP backlog to 4096.

Fixes #7379

PiperOrigin-RevId: 445541836
This commit is contained in:
Bhasker Hariharan
2022-04-29 17:40:17 -07:00
committed by gVisor bot
parent 2d9f1c3329
commit 19e9ee104a
+9 -1
View File
@@ -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",