fix: concurrent write on relay rpc/rest

This commit is contained in:
Richard Ramos 2023-02-07 18:26:07 -04:00 committed by RichΛrd
parent 2f009cb69f
commit 50e0e803eb
2 changed files with 4 additions and 0 deletions

View File

@ -71,11 +71,13 @@ func (r *RelayService) Start(ctx context.Context) {
ctx, cancel := context.WithCancel(ctx)
r.cancel = cancel
r.messagesMutex.Lock()
// Node may already be subscribed to some topics when Relay API handlers are installed. Let's add these
for _, topic := range r.node.Relay().Topics() {
r.log.Info("adding topic handler for existing subscription", zap.String("topic", topic))
r.messages[topic] = []*pb.WakuMessage{}
}
r.messagesMutex.Unlock()
r.runner.Start(ctx)
}

View File

@ -67,11 +67,13 @@ func (r *RelayService) addEnvelope(envelope *protocol.Envelope) {
}
func (r *RelayService) Start() {
r.messagesMutex.Lock()
// Node may already be subscribed to some topics when Relay API handlers are installed. Let's add these
for _, topic := range r.node.Relay().Topics() {
r.log.Info("adding topic handler for existing subscription", zap.String("topic", topic))
r.messages[topic] = make([]*pb.WakuMessage, 0)
}
r.messagesMutex.Unlock()
r.runner.Start()
}