cloudwego / cloudwego/netpoll-benchmark

TCP server 没有处理 net.Listen errors 导致 panic

Open Beginner friendly
#13 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
45
Forks
11
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

`net/rpc_server.go:36-40`
```go
func (s *rpcServer) Run(network, address string) error {
// new listener
listener, _ := net.Listen(network, address)
for {
_conn, err := listener.Accept()
```
`net/mux_server.go: 38-43`
```go
func (s *muxServer) Run(network, address string) error {
// new listener
listener, _ := net.Listen(network, address)
var conns = make([]*muxConn, 0, 1024)
for {
_conn, err := listener.Accept()
```

**To Reproduce**
搞一个 TCP receiver, 找个端口, 启动:

```bash
mkdir -p output/bin
go build -o output/bin/net_reciever ./net

python3 -m http.server 7001 >/tmp/netpoll-port-owner.log 2>&1 &
port_owner_pid=$!

./output/bin/net_reciever -addr=127.0.0.1:7001 -mode=1
rc=$?

kill "$port_owner_pid"
wait "$port_owner_pid" 2>/dev/null || true
exit "$rc"
```

**behavior**:我自己改了路径,其它没动

```text
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x26d9ac]

goroutine 1 [running]:
main.(*rpcServer).Run(0x62fc00, {0x347652?, 0x400004a738?}, {0xffffc6e95c2e?, 0x11354?})
~/app/cloudwego_netpoll_bench/net/rpc_server.go:40 +0x4c
github.com/cloudwego/netpoll-benchmark/runner/svr.Serve(0x36a6a0)
~/app/cloudwego_netpoll_bench/runner/svr/server.go:33 +0x84
main.main()
~/app/cloudwego_netpoll_bench/net/main.go:26 +0x24

```

**Environment:**

$ go env
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/hxy/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/hxy/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3082581226=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/hxy/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/hxy/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/home/hxy/app/go1.24'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/hxy/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/hxy/app/go1.24/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.6'
GOWORK=''
PKG_CONFIG='pkg-config'

**Additional context**

benchmark 运行程序也需要一个可靠的 non-zero exit,这样无效的测量结果才不会被当作成功运行

Contributor guide

Open the contributing guide

Research direction

Start with net/rpc_server.go:36-40 and net/mux_server.go:38-43, then trace how Run is called through runner/svr/server.go and net/main.go. Reproduce the occupied-port case from the issue and verify both server modes report the listen failure and the benchmark exits non-zero instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.