Comments (6)
Hey @jamesmulcahy thanks for opening this issue.
Can you provide a more detailed description of the problem you're facing? It would be awesome if you could explain in detail what you've discovered.
Do you have some code examples that I can use to reproduce it?
What you are looking for is a way to wait that the initial loading to be complete before being able to evaluate the flag?
from go-feature-flag.
What you are looking for is a way to wait that the initial loading to be complete before being able to evaluate the flag?
Yes, exactly right.
The issue right now is that if I write a test which depends on feature flag configuration, the execution of the test races against the background loading of the feature flag configuration. This leads to the test failing sporadically.
The workaround I'm using for now is to add this at the top of tests which I know are loading flags:
func WaitForInit(t *testing.T) {
require.Eventually(t, func() bool {
flags, err := ffclient.GetFlagsFromCache()
return err == nil && len(flags) > 0
}, 1*time.Second, 50*time.Millisecond)
}
But I'd prefer a more generic approach, for example, if there was a ffclient.GetInitializationChan()
which returned a channel which was closed once the initial flag load was complete. That way, I could write something like this:
ffclient.Init(...)
<-ffclient.GetInitializationChan()
Or if people wanted something more advanced/robust, they could add a timeout...
ffclient.Init(...)
select {
case <-ffclient.GetInitializationChan()
// Success!
case <-time.Tick(1 * time.Second)
// Timeout, failure...
}
I'd be happy to put together a PR along these lines (or another approach, if you have another idea/preference)
from go-feature-flag.
@jamesmulcahy I was reading the code again and I am not sure to understand why you have this problem.
The Init
function is doing the first load of the flag in a synchronous way in the same thread as the init function.
The thread is following these steps:
Init()
--> New()
--> retrieveFlagsAndUpdateCache(goFF.config, goFF.cache) // at this stage the flags are supposed to be loaded already
--> goFF.startFlagUpdaterDaemon() //We launch the daemon to update the flag in the background
You can check the initial load here.
It means that after your call of the Init
function, the loading of the flags is supposed to be already ok.
If you occur race conditions maybe something is not working as expected.
Do you have an example of a test to help me to reproduce the issue?
from go-feature-flag.
Interesting point, thanks for taking a look so closely.
EDIT: Removed incorrect theory on the bug.
I don't have an independent test that reproduces this (it's heavily coupled with some internal/private source code), but let me see if I can put one together -- rather than continuing to speculate about the behavior. I'll get back to you shortly!
from go-feature-flag.
@jamesmulcahy were you able to reproduce?
If so I will be interested to dig more in detail on the problem.
from go-feature-flag.
This issue was closed because it has been stalled for 5 days with no activity.
from go-feature-flag.
Related Issues (20)
- 👀 Open pull request on open feature contrib repositories HOT 35
- Double value for a flag converted to integer HOT 3
- (feature) Add a GCP pubsub data exporter HOT 8
- (feature) Allow force-refreshing or invalidating the cache HOT 2
- (bug) incorrect mapstructure tags in NotifierConf HOT 2
- (bug) Why canary release return same result instead following percentage weight distribution? HOT 3
- (doc) migrate docusaurus to v3
- (bug) invalid retriever: no "URL" property found for kind "gitlab" HOT 2
- (bug) The configuration for Google Cloud Storage Retriever is incorrect when read from environment variables
- (feature) Add ability for proxy to inject context HOT 2
- (change) Request to rename the folder name inside the exporter folder HOT 1
- (Go feature flag + Offline mode) <offline mode> HOT 5
- (feature) Add GitHub App retriever for Relay Proxy HOT 16
- (bug) Context int values marshall as float with in operator
- (feature) Create a mongodb retriever HOT 6
- (feature) Create a redis retriever HOT 9
- (feature) editor - Create a better rule editor HOT 2
- (feature) OpenTelemetry exporter HOT 4
- 👀 Open pull request on open feature contrib repositories HOT 35
- (bug) Generated a report for nil panics using nilaway HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-feature-flag.