-
Notifications
You must be signed in to change notification settings - Fork 20
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
Data races with feature flag poller #30
Comments
We were running into this as well, and it appears fixed by #38 (merged as commit |
indeed, thanks! |
This is not fully fixed. Here is an example: package main
import (
"sync"
"testing"
"time"
"github.com/posthog/posthog-go"
)
var pollInterval = 2 * time.Second
func nextTick() time.Duration {
now := time.Now()
elapsed := time.Duration(now.Minute()*60+now.Second()) * time.Second
remaining := pollInterval - elapsed%pollInterval
return remaining.Abs()
}
func TestRaces(t *testing.T) {
client, err := posthog.NewWithConfig("<set your API key>", posthog.Config{
PersonalApiKey: "<set your personal API key>",
Verbose: true,
NextFeatureFlagsPollingTick: nextTick,
})
if err != nil {
t.Fatal(err)
}
var wg sync.WaitGroup
for i := 0; i < 2; i += 1 {
wg.Add(1)
go func() {
defer wg.Done()
timer := time.NewTimer(nextTick())
defer timer.Stop()
<-timer.C
client.IsFeatureEnabled(posthog.FeatureFlagPayload{
Key: "hello",
DistinctId: "my-user",
})
}()
}
wg.Wait()
<-time.After(6 * time.Second)
} Test log
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SDK with feature flag poller enabled has data races:
There seem two be a couple of offenders:
poller.fetchedFlagsSuccessfullyOnce
(this and this)poller.featureFlags
and everywhere where they are read withpoller.GetFeatureFlags()
Full log: test.log
The text was updated successfully, but these errors were encountered: