Misc mutex locking things to avoid data races

This commit is contained in:
Dane Everitt
2020-07-18 16:03:25 -07:00
parent 0b9d923d15
commit 8315ff8ae1
8 changed files with 98 additions and 40 deletions

View File

@@ -27,12 +27,14 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
return errors.New("attempting to merge a data stack with an invalid UUID")
}
s.Lock()
// Merge the new data object that we have received with the existing server data object
// and then save it to the disk so it is persistent.
if err := mergo.Merge(s, src, mergo.WithOverride); err != nil {
return errors.WithStack(err)
}
// Mergo makes that previous lock disappear. Handle that by just re-locking the object.
s.Lock()
defer s.Unlock()