fix: concurrent map writes

This commit is contained in:
Richard Ramos 2022-11-09 10:13:21 -04:00 committed by RichΛrd
parent 5f65c5a9f4
commit 861f37f15a
2 changed files with 4 additions and 1 deletions

View File

@ -128,8 +128,9 @@ func (d *RelayService) postV1Subscriptions(w http.ResponseWriter, r *http.Reques
d.log.Error("subscribing to topic", zap.String("topic", strings.Replace(topicToSubscribe, "\n", "", -1)), zap.Error(err)) d.log.Error("subscribing to topic", zap.String("topic", strings.Replace(topicToSubscribe, "\n", "", -1)), zap.Error(err))
} else { } else {
d.node.Broadcaster().Unregister(&topicToSubscribe, sub.C) d.node.Broadcaster().Unregister(&topicToSubscribe, sub.C)
d.messagesMutex.Lock()
d.messages[topic] = []*pb.WakuMessage{} d.messages[topic] = []*pb.WakuMessage{}
d.messagesMutex.Unlock()
} }
} }

View File

@ -116,7 +116,9 @@ func (r *RelayService) PostV1Subscription(req *http.Request, args *TopicsArgs, r
r.log.Error("subscribing to topic", zap.String("topic", topic), zap.Error(err)) r.log.Error("subscribing to topic", zap.String("topic", topic), zap.Error(err))
return err return err
} }
r.messagesMutex.Lock()
r.messages[topic] = make([]*pb.WakuMessage, 0) r.messages[topic] = make([]*pb.WakuMessage, 0)
r.messagesMutex.Unlock()
} }
*reply = true *reply = true