fake-useragent icon indicating copy to clipboard operation
fake-useragent copied to clipboard

A weird crash during repeated calls to `fakeuseragent.Random()`

Open ashishb opened this issue 3 years ago • 2 comments

panic: runtime error: index out of range [-1]

goroutine 102 [running]:
math/rand.(*rngSource).Uint64(...)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rng.go:249
math/rand.(*rngSource).Int63(0xffffffffffffffff?)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rng.go:234 +0x90
math/rand.(*Rand).Int63(...)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rand.go:84
math/rand.(*Rand).Int31(...)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rand.go:98
math/rand.(*Rand).Int31n(0x140003b0060, 0xbb8)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rand.go:133 +0x50
math/rand.(*Rand).Intn(0x140016a7a18?, 0x14002236be0?)
	/opt/homebrew/Cellar/go/1.18.3/libexec/src/math/rand/rand.go:171 +0x34
github.com/EDDYCJY/fake-useragent/useragent.(*useragent).GetAllRandom(0x140016a7ab8?)
	/Users/ashishb/go/pkg/mod/github.com/!e!d!d!y!c!j!y/[email protected]/useragent/warehouse.go:50 +0x12c
github.com/EDDYCJY/fake-useragent.(*browser).Random(...)
	/Users/ashishb/go/pkg/mod/github.com/!e!d!d!y!c!j!y/[email protected]/browser.go:61
github.com/EDDYCJY/fake-useragent.Random(...)
...

ashishb avatar Jul 25 '22 18:07 ashishb

I belive the race condition comes from https://github.com/eddycjy/fake-useragent/blob/master/useragent/warehouse.go#L39 being outside the lock

ashishb avatar Jul 25 '22 18:07 ashishb

Same issue occurs at same position.

fgy58963 avatar Oct 09 '22 02:10 fgy58963