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: ReadFromUDP falls into busy waiting on empty UDP packet #59704

Closed
fumiama opened this issue Apr 19, 2023 · 1 comment
Closed

net: ReadFromUDP falls into busy waiting on empty UDP packet #59704

fumiama opened this issue Apr 19, 2023 · 1 comment

Comments

@fumiama
Copy link

fumiama commented Apr 19, 2023

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

$ go version
go version go1.20.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes, this is the latest version.

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/rumia/Library/Caches/go-build"
GOENV="/Users/rumia/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/rumia/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rumia/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/rumia/Documents/src/alpacapi/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/45/fs2wrr5548dbhlwc0j99_js40000gp/T/go-build815319731=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is a small test.

package main

import (
	"net"
	"net/netip"
	"testing"
)

func TestOnEmptyUDP(t *testing.T) {
	listener, err := net.ListenUDP("udp", net.UDPAddrFromAddrPort(netip.MustParseAddrPort("127.0.0.1:8888")))
	if err != nil {
		t.Fatal(err)
	}
	t.Log("listening on", listener.LocalAddr())
	buf := make([]byte, 4096)
	nzerocnt := 0
	go func() {
		conn, err := net.DialUDP("udp", nil, net.UDPAddrFromAddrPort(netip.MustParseAddrPort("127.0.0.1:8888")))
		if err != nil {
			panic(err)
		}
		_, _ = conn.Write(nil)
		_ = conn.Close()
	}()
	for n, remo, err := listener.ReadFromUDP(buf); err == nil; t.Log("recv from", remo) {
		if n == 0 {
			nzerocnt++
			if nzerocnt >= 4096 {
				t.Fatal("unexpected zero-loop")
			}
		}
	}
}

What did you expect to see?

The test will reach a timeout after 30s.

What did you see instead?

unexpected zero-loop triggered.

2CA8C6160F87B321A9BD489362031A32

8A4FC8D40991F39F54DD717D63732B8E

D2C6284B4782CF7FF1F4A096DCE000E9

B8AC2FA74D32B5E5C4A4120C8B77AFD8

@fumiama
Copy link
Author

fumiama commented Apr 19, 2023

i got a mistake. sorry.

@fumiama fumiama closed this as completed Apr 19, 2023
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

1 participant