Navigation Menu

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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Linux
Milestone

Comments

@lexand
Copy link

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

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 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 cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 22, 2020
@cagedmantis
Copy link
Contributor

/cc @mikioh @bradfitz @ianlancetaylor

@gopherbot
Copy link

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>
@golang golang locked and limited conversation to collaborators Oct 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Linux
Projects
None yet
Development

No branches or pull requests

4 participants