Closed Milk-Tang closed 4 weeks ago
Can you give me your test scenario? How to reproduce it here? What are the usecases?
uniqueValues[dataType] = append(uniqueValues[dataType], value)
This line definitely not safe for concurrent
Can you give me your test scenario? How to reproduce it here? What are the usecases?
Simply put, I used the faker. Username (options. WithGenerateUniqueValues (true))
method in concurrent use cases
Happening in v4.4.1
. Here's a a redacted panic occurring when tests generating fake IP addresses are run with t.Parallel()
fatal error: concurrent map writes
goroutine 32 [running]:
github.com/go-faker/faker/v4.generateUnique({0x102a6477f, 0x4}, 0x140001a8dc8)
/Users/ornj/go/pkg/mod/github.com/go-faker/faker/v4@v4.4.1/faker.go:1384 +0x198
github.com/go-faker/faker/v4.singleFakeData({0x102a6477f, 0x4}, 0x140001a8dc8, {0x140001a8db8?, 0x140001a8db8?, 0x1027b0cf4?})
/Users/ornj/go/pkg/mod/github.com/go-faker/faker/v4@v4.4.1/faker.go:1394 +0x68
github.com/go-faker/faker/v4.IPv6(...)
/Users/ornj/go/pkg/mod/github.com/go-faker/faker/v4@v4.4.1/internet.go:239
...
testing.tRunner(0x140001a24e0, 0x140000d26a0)
/usr/local/go/1.21.4/libexec/src/testing/testing.go:1595 +0xe8
created by testing.(*T).Run in goroutine 23
/usr/local/go/1.21.4/libexec/src/testing/testing.go:1648 +0x33c
Hi @Milk-Tang and @ornj
Thanks for the issue, and I'm sorry for the late update. Can you try v4.4.2, it should be fixed.
while I'm using
faker.Username(options.WithGenerateUniqueValues(true))
in a concurrent scenario, "concurrent map writes" happened in the funcgenerateUnique
: https://github.com/go-faker/faker/blob/91fd09b0f81ca8520ead46dac24425c5db029861/faker.go#L1328-L1337