Switch to sync.Map because go maps are unsound
continuous-integration/drone/pr Build is passing Details

Sarah Jamie Lewis 2 months ago
parent 2e59cc43ab
commit cccb97d5f0

@ -6,15 +6,20 @@ import "sync"
// examples of experiments include File Sharing, Profile Images and Groups.
type Experiments struct {
enabled bool
experiments map[string]bool
lock sync.Mutex
experiments sync.Map
// InitExperiments encapsulates a set of experiments separate from their storage in GlobalSettings.
func InitExperiments(enabled bool, experiments map[string]bool) Experiments {
var syncExperiments sync.Map
for experiment, set := range experiments {
syncExperiments.Store(experiment, set)
return Experiments{
enabled: enabled,
experiments: experiments,
experiments: syncExperiments,
@ -28,12 +33,9 @@ func (e *Experiments) IsEnabled(experiment string) bool {
return false
// go will sometimes panic if we do not lock this read-only map...
defer e.lock.Unlock()
enabled, exists := e.experiments[experiment]
enabled, exists := e.experiments.Load(experiment)
if !exists {
return false
return enabled
return enabled.(bool)