fix: flaky panic on relay unsubscribe (#1201)

This commit is contained in:
Igor Sirotin 2024-08-22 05:46:03 +01:00 committed by GitHub
parent 8ff8779bb0
commit 1472b17d39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 20 deletions

View File

@ -459,16 +459,14 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co
defer w.topicsMutex.Unlock() defer w.topicsMutex.Unlock()
for pubSubTopic, cTopics := range pubSubTopicMap { for pubSubTopic, cTopics := range pubSubTopicMap {
cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...)
pubsubUnsubscribe := false pubsubUnsubscribe := false
sub, ok := w.topics[pubSubTopic] topicData, ok := w.topics[pubSubTopic]
if !ok { if !ok {
w.log.Error("not subscribed to topic", zap.String("topic", pubSubTopic)) w.log.Error("not subscribed to topic", zap.String("topic", pubSubTopic))
return errors.New("not subscribed to topic") return errors.New("not subscribed to topic")
} }
topicData, ok := w.topics[pubSubTopic] cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...)
if ok {
//Remove relevant subscription //Remove relevant subscription
for subID, sub := range topicData.contentSubs { for subID, sub := range topicData.contentSubs {
if sub.contentFilter.Equals(cfTemp) { if sub.contentFilter.Equals(cfTemp) {
@ -480,16 +478,9 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co
if len(topicData.contentSubs) == 0 { if len(topicData.contentSubs) == 0 {
pubsubUnsubscribe = true pubsubUnsubscribe = true
} }
} else {
//Should not land here ideally
w.log.Error("pubsub subscriptions exists, but contentSubscription doesn't for contentFilter",
zap.String("pubsubTopic", pubSubTopic), zap.Strings("contentTopics", cTopics))
return errors.New("unexpected error in unsubscribe")
}
if pubsubUnsubscribe { if pubsubUnsubscribe {
err = w.unsubscribeFromPubsubTopic(sub) err = w.unsubscribeFromPubsubTopic(topicData)
if err != nil { if err != nil {
return err return err
} }