Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lexand opened this issue Sep 18, 2020 · 3 comments

Comments

@lexand
Copy link

@lexand lexand commented Sep 18, 2020

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:*  
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 18, 2020

Change https://golang.org/cl/255898 mentions this issue: net: increase tcp backlog size on Linux

@odeke-em odeke-em changed the title tcp backlog size truncated to max uint16 instead of uint32 net: TCP backlog size truncated to max uint16 instead of uint32 yet was increased to uint32 in 2015 Linux Sep 18, 2020
@odeke-em odeke-em changed the title net: TCP backlog size truncated to max uint16 instead of uint32 yet was increased to uint32 in 2015 Linux net: TCP backlog size truncated to max uint16 instead of uint32 yet was increased to uint32 in Linux kernel 4.0 from 2015 Sep 18, 2020
@odeke-em odeke-em added the OS-Linux label Sep 18, 2020
@odeke-em odeke-em added this to the Go1.16 milestone Sep 18, 2020
@odeke-em odeke-em changed the title net: TCP backlog size truncated to max uint16 instead of uint32 yet was increased to uint32 in Linux kernel 4.0 from 2015 net: TCP backlog size truncated to max(uint16)-1 instead of uint32 yet was increased to uint32 in Linux kernel 4.1 from 2015 Sep 19, 2020
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Sep 22, 2020

@gopherbot gopherbot closed this in 0a9dd47 Sep 23, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 16, 2020

Change https://golang.org/cl/262938 mentions this issue: doc: add change to net listener backlog size

gopherbot pushed a commit that referenced this issue Oct 21, 2020
Updates #41470

Change-Id: Iebd3a339504aa7f8834853d6a740557fb3bce3ef
Reviewed-on: https://go-review.googlesource.com/c/go/+/262938
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.