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

tcp backlog size truncated to max uint16 instead of uint32 #5

Open
lexand opened this issue Sep 18, 2020 · 4 comments
Open

tcp backlog size truncated to max uint16 instead of uint32 #5

lexand opened this issue Sep 18, 2020 · 4 comments

Comments

@lexand
Copy link

lexand commented Sep 18, 2020

see related golang/go#41470

$ sudo sysctl -w net.core.somaxconn=196602
net.core.somaxconn = 196602
$ 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
package main

import (
	"net/http"

	"github.com/valyala/fasthttp"
	"github.com/valyala/tcplisten"
)

func main() {
	s := &fasthttp.Server{
		DisableKeepalive:             true,
		DisablePreParseMultipartForm: true,
		Handler: func(ctx *fasthttp.RequestCtx) {
			ctx.SetStatusCode(http.StatusNoContent)
		},
	}

	tcpCfg := &tcplisten.Config{
		ReusePort:   true,
		DeferAccept: false,
		FastOpen:    true,
	}
	l, _ := tcpCfg.NewListener("tcp4", "0.0.0.0:8888")
	_ = s.Serve(l)
}

Expected

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

Actual

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

But this code works well

```go
package main

import (
	"net/http"

	"github.com/valyala/fasthttp"
	"github.com/valyala/tcplisten"
)

func main() {
	s := &fasthttp.Server{
		DisableKeepalive:             true,
		DisablePreParseMultipartForm: true,
		Handler: func(ctx *fasthttp.RequestCtx) {
			ctx.SetStatusCode(http.StatusNoContent)
		},
	}

	tcpCfg := &tcplisten.Config{
		ReusePort:   true,
		DeferAccept: false,
		FastOpen:    true,
                Backlog:     196602,
	}
	l, _ := tcpCfg.NewListener("tcp4", "0.0.0.0:8888")
	_ = s.Serve(l)
}
$ ss -l | grep 8888
tcp               LISTEN              0                    196602                                                                                        0.0.0.0:8888                                                 0.0.0.0:*  
@u5surf
Copy link

u5surf commented Dec 1, 2020

Hi, @lexand
Because valyala/tcplisten calls syscall.Listen(fd, backlog) directly now, It can be set backlog size under system requirements if we use tcplisten.Config.Backlog.
Unless we use config, it adopt soMaxConn for backlog.
Backlog size is truncate to max(uint16)-1 by soMaxConn which is same behavior to net.Listen as you mentioned the issue(golang/go#41470)

@lexand
Copy link
Author

lexand commented Dec 1, 2020

Hi, @u5surf

In issue(golang/go#41470) and in this issue(#5) I point only that code has not actual behaviour for new linux kernels. As new kernels store so_max_conn in uint32.

Default truncating to truncate to max(uint16)-1 is actual for very old kernels.

@u5surf
Copy link

u5surf commented Dec 4, 2020

I had backported https://go-review.googlesource.com/c/go/+/255898/
check it out #6

@lexand
Copy link
Author

lexand commented Dec 4, 2020

thats works as expected
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants