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: wrong sysctl name on FreeBSD #23653

Closed
sternix opened this issue Feb 1, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@sternix
Copy link

commented Feb 1, 2018

Please answer these questions before submitting your issue. Thanks!

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

go version go1.10rc1 freebsd/amd64

What operating system and processor architecture are you using (go env)?

go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/sternix/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="freebsd"
GOOS="freebsd"
GOPATH="/home/sternix/go"
GORACE=""
GOROOT="/opt/go/1_10rc1/go"
GOTMPDIR=""
GOTOOLDIR="/opt/go/1_10rc1/go/pkg/tool/freebsd_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build393653327=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
        "fmt"
        "log"
        "net/http"
)

func index(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w,"Hello World")
}

func main() {
        http.HandleFunc("/",index)

        if err := http.ListenAndServe(":8080",nil); err != nil {
                log.Fatal(err)
        }
}

What did you expect to see?

compiled with go 1.9.2
% netstat -Lan
Current listen queue sizes (qlen/incqlen/maxqlen)
Proto Listen Local Address
tcp46 0/0/65535 *.8080

compiled with go 1.10rc1
% netstat -Lan
Current listen queue sizes (qlen/incqlen/maxqlen)
Proto Listen Local Address
tcp46 0/0/128 *.8080

i want to see
tcp46 0/0/65535 *.8080

i suspect the
e76ae8a#diff-871343a875351732bbc01da3b532b485
the pr cause this

because FreeBSD has " kern.ipc.soacceptqueue "," kern.ipc.somaxconn " sysctl's but no
" kern.ipc.acceptqueue "

% sysctl kern.ipc.soacceptqueue
kern.ipc.soacceptqueue: 65536

% sysctl kern.ipc.somaxconn
kern.ipc.somaxconn: 65536

% sysctl kern.ipc.acceptqueue
sysctl: unknown oid 'kern.ipc.acceptqueue'

package main

import (
        "syscall"
        "fmt"
)

func maxListenerBacklog() int {
        n, err := syscall.SysctlUint32("kern.ipc.acceptqueue")
        if n == 0 || err != nil {
                fmt.Printf("Error: %s\n",err)
                return syscall.SOMAXCONN

                // https://github.com/golang/go/blob/master/src/syscall/zerrors_freebsd_amd64.go#L1288
                // SOMAXCONN = 0x80
                // defaults to 128
        }

        // FreeBSD stores the backlog in a uint16, as does Linux.
        // Assume the other BSDs do too. Truncate number to avoid wrapping.
        // See issue 5030.
        if n > 1<<16-1 {
                n = 1<<16 - 1
        }
        return int(n)
}

func maxListenerBacklogCorrect() int {
        n, err := syscall.SysctlUint32("kern.ipc.soacceptqueue")
        if n == 0 || err != nil {
                return syscall.SOMAXCONN
        }
        // FreeBSD stores the backlog in a uint16, as does Linux.
        // Assume the other BSDs do too. Truncate number to avoid wrapping.
        // See issue 5030.
        if n > 1<<16-1 {
                n = 1<<16 - 1
        }
        return int(n)
}

func main() {
        bl := maxListenerBacklog()
        fmt.Printf("Wrong Backlog: %d\n",bl)

        bl = maxListenerBacklogCorrect()
        fmt.Printf("Correct Backlog: %d\n",bl)
}

after all, i think the line in
https://github.com/golang/go/blob/master/src/net/sock_bsd.go#L23
might be
n, err = syscall.SysctlUint32("kern.ipc.soacceptqueue")

Can you help.

@tklauser tklauser changed the title Wrong sysctl name syscall: wrong sysctl name on FreeBSD Feb 1, 2018

@tklauser tklauser changed the title syscall: wrong sysctl name on FreeBSD net: wrong sysctl name on FreeBSD Feb 1, 2018

@tklauser tklauser added this to the Go1.11 milestone Feb 1, 2018

@tklauser

This comment has been minimized.

Copy link
Member

commented Feb 1, 2018

/cc @mikioh

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 1, 2018

Good catch, thanks for the report.

@mikioh mikioh modified the milestones: Go1.11, Go1.10 Feb 1, 2018

@gopherbot

This comment has been minimized.

Copy link

commented Feb 1, 2018

Change https://golang.org/cl/91317 mentions this issue: net: fix the kernel state name for TCP listen queue on FreeBSD

@gopherbot gopherbot closed this in cbe1a61 Feb 2, 2018

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

Reopening for go1.10.

@mikioh mikioh reopened this Feb 2, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

We're going to merge master to the Go 1.10 branch before the release, so no need to keep this issue open for that.

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 2, 2018

Good to hear that.

@mikioh mikioh closed this Feb 2, 2018

@golang golang locked and limited conversation to collaborators Feb 2, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.