Skip to content

Commit 95a292b

Browse files
aiharosmjuraga
authored andcommitted
BUG/MEDIUM: ensure no startup race possible when creating Configuration struct
1 parent f269080 commit 95a292b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

configuration/configuration.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ type Configuration struct {
166166
MapSync *MapSync `yaml:"-"`
167167
}
168168

169+
var cfgInitOnce sync.Once
170+
169171
// Get returns pointer to configuration
170172
func Get() *Configuration {
171-
if cfg == nil {
173+
cfgInitOnce.Do(func() {
172174
cfg = &Configuration{}
173175
cfg.initSignalHandler()
174176
cfg.Notify.BootstrapKeyChanged = NewChanNotify()
@@ -188,7 +190,7 @@ func Get() *Configuration {
188190
}
189191

190192
cfg.Cmdline.Store(sb.String())
191-
}
193+
})
192194
return cfg
193195
}
194196

0 commit comments

Comments
 (0)