@@ -89,32 +89,30 @@ func InitialDatafile(datafile []byte) OptionFunc {
89
89
func (cm * PollingProjectConfigManager ) SyncConfig (datafile []byte ) {
90
90
var e error
91
91
var code int
92
+
93
+ closeMutex := func (e error ) {
94
+ cm .err = e
95
+ cm .configLock .Unlock ()
96
+ }
97
+
92
98
if len (datafile ) == 0 {
93
99
datafile , code , e = cm .requester .Get ()
94
100
95
101
if e != nil {
96
102
cmLogger .Error (fmt .Sprintf ("request returned with http code=%d" , code ), e )
97
- cm .err = nil
98
- if cm .projectConfig == nil {
99
- cm .err = e
100
- }
103
+ cm .configLock .Lock ()
104
+ closeMutex (e )
101
105
return
102
106
}
103
107
}
104
108
105
109
projectConfig , err := datafileprojectconfig .NewDatafileProjectConfig (datafile )
106
110
107
111
cm .configLock .Lock ()
108
- closeMutex := func () {
109
- cm .err = nil
110
- if cm .projectConfig == nil {
111
- cm .err = err
112
- }
113
- cm .configLock .Unlock ()
114
- }
112
+
115
113
if err != nil {
116
114
cmLogger .Error ("failed to create project config" , err )
117
- closeMutex ()
115
+ closeMutex (err )
118
116
return
119
117
}
120
118
@@ -124,12 +122,12 @@ func (cm *PollingProjectConfigManager) SyncConfig(datafile []byte) {
124
122
}
125
123
if projectConfig .GetRevision () == previousRevision {
126
124
cmLogger .Debug (fmt .Sprintf ("No datafile updates. Current revision number: %s" , cm .projectConfig .GetRevision ()))
127
- closeMutex ()
125
+ closeMutex (nil )
128
126
return
129
127
}
130
128
cmLogger .Debug (fmt .Sprintf ("New datafile set with revision: %s. Old revision: %s" , projectConfig .GetRevision (), previousRevision ))
131
129
cm .projectConfig = projectConfig
132
- closeMutex ()
130
+ closeMutex (nil )
133
131
134
132
if cm .notificationCenter != nil {
135
133
projectConfigUpdateNotification := notification.ProjectConfigUpdateNotification {
@@ -182,7 +180,10 @@ func NewPollingProjectConfigManager(sdkKey string, pollingMangerOptions ...Optio
182
180
func (cm * PollingProjectConfigManager ) GetConfig () (pkg.ProjectConfig , error ) {
183
181
cm .configLock .RLock ()
184
182
defer cm .configLock .RUnlock ()
185
- return cm .projectConfig , cm .err
183
+ if cm .projectConfig == nil {
184
+ return cm .projectConfig , cm .err
185
+ }
186
+ return cm .projectConfig , nil
186
187
}
187
188
188
189
// OnProjectConfigUpdate registers a handler for ProjectConfigUpdate notifications
0 commit comments