I got error `fatal error: concurrent map writes` ...
# ask-questions
c
I got error
fatal error: concurrent map writes
while running a multi-threaded benchmark with single instance *growthbook.GrowthBook (in Go SDKs)
Copy code
func getGBInstance() *growthbook.GrowthBook {
    context := growthbook.NewContext().
       WithClientKey("keyxxxxx").
       WithCacheTTL(10 * time.Second)

    gb := growthbook.New(context)
    gb.LoadFeatures(&growthbook.FeatureRepoOptions{
       AutoRefresh: true,
    })

    return gb
}

func evaluateFeature(gb *growthbook.GrowthBook, attVal string) bool {
    gb.WithAttributes(growthbook.Attributes{"id": attVal})
    rs := gb.EvalFeature("enable-dark-mode").On
    return rs
}
func BenchmarkEvaluateFeatureParallel(b *testing.B) {
    gbInstance = getGBInstance()
    b.ResetTimer()

    b.RunParallel(func(pb *testing.PB) {
       var wg sync.WaitGroup

       for pb.Next() {
          wg.Add(1)
          go func() {
             attVal := "some-random-value"
             _ = evaluateFeature(gbInstance, attVal)
             wg.Done()
          }()
       }
       wg.Wait()
    })
}
r
@cool-elephant-31930 has opened an issue Close Issue button
Our official support hours are 6:30am - 5pm Pacific Time, Monday through Friday. You may occasionally hear from us outside of these hours. Your support request has been logged in our system. Our support team will get back to you very soon!
f
How many connections did you have?
c
I only use go
go test -bench=.
command to run benchmark above function.
Copy code
b.SetParallelism(change_me)
When I set any value for change_me before run benchmark, I also got error
fatal error: concurrent map read and map write
b
Hello, Nam, I'm tagging the person who maintains the Go SDK in hopes he can answer your question: @alert-dream-63361 In the future, you can post questions related to the Go SDK in the #sdk-golang channel 😄
👀 1