Fix Map Panic

This commit is contained in:
Sarah Jamie Lewis 2023-02-25 07:19:12 -08:00
parent 0e49d70d65
commit 195e048410
1 changed files with 7 additions and 0 deletions

View File

@ -1,10 +1,13 @@
package model package model
import "sync"
// Experiments are optional functionality that can be enabled/disabled by an application either completely or individually. // Experiments are optional functionality that can be enabled/disabled by an application either completely or individually.
// examples of experiments include File Sharing, Profile Images and Groups. // examples of experiments include File Sharing, Profile Images and Groups.
type Experiments struct { type Experiments struct {
enabled bool enabled bool
experiments map[string]bool experiments map[string]bool
lock sync.Mutex
} }
// InitExperiments encapsulates a set of experiments separate from their storage in GlobalSettings. // InitExperiments encapsulates a set of experiments separate from their storage in GlobalSettings.
@ -24,6 +27,10 @@ func (e *Experiments) IsEnabled(experiment string) bool {
// todo handle default-enabled functionality // todo handle default-enabled functionality
return false return false
} }
// go will sometimes panic if we do not lock this read-only map...
e.lock.Lock()
defer e.lock.Unlock()
enabled, exists := e.experiments[experiment] enabled, exists := e.experiments[experiment]
if !exists { if !exists {
return false return false