Skip to content

net: TCP backlog size truncated to max(uint16)-1 instead of uint32 yet was increased to uint32 in Linux kernel 4.1 from 2015 #41470

@lexand

Description

@lexand

What version of Go are you using (go version)?

$ go version
go version go1.15 linux/amd64

$ uname -a
Linux alex-work 4.15.0-117-generic #118-Ubuntu SMP Fri Sep 4 20:02:41 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Does this issue reproduce with the latest release?

yes

What did you do?

$ sudo sysctl -w net.core.somaxconn=196602
net.core.somaxconn = 196602
	_ = http.ListenAndServe("0.0.0.0:8888", http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		writer.WriteHeader(http.StatusNoContent)
	}))

What did you expect to see?

$ ss -l | grep 8888
tcp               LISTEN              0                    196602                                                                                              *:8888                                                       *:*                  

What did you see instead?

$ ss -l | grep 8888
tcp               LISTEN              0                    65535                                                                                              *:8888                                                       *:*                  

Issue #5030 is not actual for new kernels as

u32			sk_max_ack_backlog;

Below code is working well

package main

import (
	"fmt"
	"net"
	"net/http"
	"os"
	"syscall"
)

func main() {
	tcpAddr, err := net.ResolveTCPAddr("tcp4", "0.0.0.0:8888")
	if err != nil {
		panic(err)
	}
	var sa syscall.SockaddrInet4
	sa.Port = tcpAddr.Port
	copy(sa.Addr[:], tcpAddr.IP.To4())

	fd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM|syscall.SOCK_NONBLOCK|syscall.SOCK_CLOEXEC, syscall.IPPROTO_TCP)
	if err != nil {
		panic(err)
	}

	if err = syscall.Bind(fd, &sa); err != nil {
		panic(err)
	}

        // this value will not be truncated by kernel
	backlog := 196602
	if err = syscall.Listen(fd, backlog); err != nil {
		panic(err)
	}

	name := fmt.Sprintf("backlog.%d.%s.%s", os.Getpid(), "tcp4", "0.0.0.0:8888")
	file := os.NewFile(uintptr(fd), name)
	ln, err := net.FileListener(file)
	if err != nil {
		_ = file.Close()
		panic(err)
	}

	if err = file.Close(); err != nil {
		_ = ln.Close()
		panic(err)
	}

	_ = http.Serve(ln, http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
		writer.WriteHeader(http.StatusNoContent)
	}))
}
r$ ss -l | grep 8888
tcp               LISTEN              0                    196602                                                                                       0.0.0.0:8888                                                 0.0.0.0:*  

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Linux

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions