Defend against a potential race condition in registering push stats providers.

Signed-off-by: David Weitzman <dweitzman@pinterest.com>
This commit is contained in:
David Weitzman 2018-05-04 14:27:29 -07:00
Родитель a3d03d418c
Коммит 05ac7222c0
1 изменённых файлов: 3 добавлений и 0 удалений

Просмотреть файл

@ -110,11 +110,14 @@ type PushBackend interface {
}
var pushBackends = make(map[string]PushBackend)
var pushBackendsLock sync.Mutex
var once sync.Once
// RegisterPushBackend allows modules to register PushBackend implementations.
// Should be called on init().
func RegisterPushBackend(name string, backend PushBackend) {
pushBackendsLock.Lock()
defer pushBackendsLock.Unlock()
if _, ok := pushBackends[name]; ok {
log.Fatalf("PushBackend %s already exists; can't register the same name multiple times", name)
}