sync map woes
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2021-09-03 13:03:08 -07:00
parent 1938f14837
commit cef991a5ef
1 changed files with 6 additions and 1 deletions

View File

@ -113,10 +113,15 @@ func (pa *PeerApp) listen() {
func (pa *PeerApp) SendMessage(message model2.PeerMessage) error {
if message.Context == event.ContextGetVal {
pa.getValRequests.Store(message.ID, string(message.Data))
// sync map is apparently not guaranteed to be consistent
_, ok := pa.getValRequests.Load(message.ID)
for !ok {
log.Debugf("retrying to load value map...")
_, ok = pa.getValRequests.Load(message.ID)
}
}
serialized, err := json.Marshal(message)
if err == nil {
//log.Debugf("sending plaintext of length %v", len(serialized))
pa.connection.Send(serialized)
return nil
}