SkyAPM / go2sky

Distributed tracing and monitor SDK in Go for Apache SkyWalking APM
https://skywalking.apache.org/
Apache License 2.0
447 stars 122 forks source link

I get a panic msg #109

Closed taidixiong closed 3 years ago

taidixiong commented 3 years ago

https://github.com/SkyAPM/go2sky/blob/6c4fc8fa5f1e4a9a6ff57286f721cc8f50d21f13/sampler.go#L55

rand.Intn(100) when it work on high qps.

/opt/soft/go/src/net/http/server.go:2933 +0x35c

2021/05/17 21:03:16 runtime error: index out of range [-1] goroutine 225695528 [running]: runtime/debug.Stack(0x2bc3920, 0xc03ee86d20, 0xc0ec7911d0) /opt/soft/go/src/runtime/debug/stack.go:24 +0x9d ........................ /opt/soft/go/src/runtime/panic.go:967 +0x15d math/rand.(rngSource).Uint64(...) /opt/soft/go/src/math/rand/rng.go:249 math/rand.(rngSource).Int63(0xc002583500, 0x7f769d653108) /opt/soft/go/src/math/rand/rng.go:234 +0x9d math/rand.(Rand).Int63(...) /opt/soft/go/src/math/rand/rand.go:85 math/rand.(Rand).Int31(...) /opt/soft/go/src/math/rand/rand.go:99 math/rand.(Rand).Int31n(0xc0038da1e0, 0x1899cbbd00000064, 0x1045f68) /opt/soft/go/src/math/rand/rand.go:134 +0x5f math/rand.(Rand).Intn(0xc0038da1e0, 0x64, 0x0) /opt/soft/go/src/math/rand/rand.go:172 +0x45

kezhenxu94 commented 3 years ago

According to https://golang.org/pkg/math/rand/ ,

 The default Source is safe for concurrent use by multiple goroutines, but Sources created by NewSource are not.

And

https://github.com/SkyAPM/go2sky/blob/6c4fc8fa5f1e4a9a6ff57286f721cc8f50d21f13/sampler.go#L59

taidixiong commented 3 years ago

i fixed it,thx