-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as not planned
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.
Description
Go version
go version go1.24.0 linux/amd64
Output of go env in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/zchenyu/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/zchenyu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build814464281=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/zchenyu/tmp/go/go.mod'
GOMODCACHE='/home/zchenyu/go/pkg/mod'
GONOPROXY='github.com/fw-ai'
GONOSUMDB='github.com/fw-ai'
GOOS='linux'
GOPATH='/home/zchenyu/go'
GOPRIVATE='github.com/fw-ai'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/zchenyu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/zchenyu/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/zchenyu/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.0.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'What did you do?
Eerily similar to #51015
Our generation code is a little more complex (has prefixes/suffixes) than the original post, hence the strings.Builder, but it's the same in spirit.
We use GenerateID in an RPC service and after several months (years?) of no issue, for a period of a few hours, we were consistently generating the string aaaaaaaa in about ~30% of calls. Other timing info:
- The issue was observed only in one server replica, the others were okay
- Only started several hours/days after the server was started, and it stopped by itself
- Roughly speaking, each RPC calls GenerateID once. Not all calls resulted in the string of
aaaaaaaa, only ~30%. The other generated strings looked normal.
I also cannot reproduce the issue in a small program.
const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
var seededRand = rand.New(rand.NewSource(time.Now().UnixNano()))
func GenerateID(length int) string {
var sb strings.Builder
sb.Grow(length)
for i := 0; i < length; i++ {
sb.WriteByte(charset[seededRand.Intn(len(charset))])
}
return sb.String()
}
In any case, it seems seeding is no longer necessary after go1.20, so we will just remove the NewSource and use the default (concurrency safe) one. Hopefully that fixes the problem.
What did you see happen?
Consistently see 0's returned by Intn()
What did you expect to see?
Random numbers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.