From 734289043aba8669d0fd999d3157ffa9338ed728 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Mon, 19 Jun 2017 11:12:08 -0400 Subject: [PATCH] Fix race in gossip initialization --- protokube/pkg/gossip/mesh/state.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/protokube/pkg/gossip/mesh/state.go b/protokube/pkg/gossip/mesh/state.go index a6d9765a78..48646c663a 100644 --- a/protokube/pkg/gossip/mesh/state.go +++ b/protokube/pkg/gossip/mesh/state.go @@ -90,8 +90,8 @@ func (s *state) snapshot() *gossip.GossipStateSnapshot { } s.lastSnapshot = snapshot return snapshot - } + func (s *state) put(key string, data []byte) { s.mtx.Lock() defer s.mtx.Unlock() @@ -102,6 +102,11 @@ func (s *state) put(key string, data []byte) { Data: data, Version: now, } + + if s.data.Records == nil { + s.data.Records = make(map[string]*KVStateRecord) + } + s.data.Records[key] = v s.version++ } @@ -116,6 +121,10 @@ func (s *state) updateValues(removeKeys []string, putEntries map[string]string) now := s.now() + if s.data.Records == nil { + s.data.Records = make(map[string]*KVStateRecord) + } + for _, k := range removeKeys { v := &KVStateRecord{ Tombstone: true, @@ -161,6 +170,14 @@ var _ mesh.GossipData = &KVState{} func mergeKVState(dest *KVState, src *KVState, changes *KVState) bool { changed := false + if dest.Records == nil { + dest.Records = make(map[string]*KVStateRecord) + } + + if changes != nil && changes.Records == nil { + changes.Records = make(map[string]*KVStateRecord) + } + for k, update := range src.Records { existing, found := dest.Records[k] if found && existing.Version >= update.Version {