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

concurrent map writes happened while use "options.WithGenerateUniqueValues(true)" #29

Open
Milk-Tang opened this issue Jun 15, 2023 · 3 comments

Comments

@Milk-Tang
Copy link

while I'm using faker.Username(options.WithGenerateUniqueValues(true)) in a concurrent scenario,
"concurrent map writes" happened in the func generateUnique

faker/faker.go

Lines 1328 to 1337 in 91fd09b

func generateUnique(dataType string, fn func() interface{}) (interface{}, error) {
for i := 0; i < maxRetry; i++ {
value := fn()
if !slice.ContainsValue(uniqueValues[dataType], value) { // Retry if unique value already found
uniqueValues[dataType] = append(uniqueValues[dataType], value)
return value, nil
}
}
return reflect.Value{}, fmt.Errorf(fakerErrors.ErrUniqueFailure, dataType)
}

@bxcodec
Copy link
Contributor

bxcodec commented Jun 17, 2023

Can you give me your test scenario? How to reproduce it here? What are the usecases?

@bxcodec
Copy link
Contributor

bxcodec commented Jun 17, 2023

uniqueValues[dataType] = append(uniqueValues[dataType], value) 

This line definitely not safe for concurrent

@Milk-Tang
Copy link
Author

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

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

2 participants