Make an actual deep-copy of the state

Before this patch this was creating a shallow copy, as the KVState was
copied but the underlying map (Records) wasn't.

Related to #7134
This commit is contained in:
Thomas Jackson 2019-07-03 10:11:04 -07:00
parent 956e223226
commit 7fb37fe3f7
1 changed files with 4 additions and 2 deletions

View File

@ -150,8 +150,10 @@ func (s *state) updateValues(removeKeys []string, putEntries map[string]string)
func (s *state) getData() *KVState {
s.mtx.RLock()
defer s.mtx.RUnlock()
d := &KVState{}
*d = s.data
// make a deep-copy. To avoid a bunch of reflection etc. this simply marshals and unmarshals
b, _ := proto.Marshal(&s.data)
d, _ := DecodeKVState(b)
return d
}