Skip to content

Commit

Permalink
fix_: flaky panic on relay unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin committed Aug 21, 2024
1 parent 8ff8779 commit 8709afb
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions waku/v2/protocol/relay/waku_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,37 +459,28 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co
defer w.topicsMutex.Unlock()

for pubSubTopic, cTopics := range pubSubTopicMap {
cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...)
pubsubUnsubscribe := false
sub, ok := w.topics[pubSubTopic]
topicData, ok := w.topics[pubSubTopic]
if !ok {
w.log.Error("not subscribed to topic", zap.String("topic", pubSubTopic))
return errors.New("not subscribed to topic")
}

topicData, ok := w.topics[pubSubTopic]
if ok {
//Remove relevant subscription
for subID, sub := range topicData.contentSubs {
if sub.contentFilter.Equals(cfTemp) {
sub.Unsubscribe()
delete(topicData.contentSubs, subID)
}
}

if len(topicData.contentSubs) == 0 {
pubsubUnsubscribe = true
cfTemp := waku_proto.NewContentFilter(pubSubTopic, cTopics...)
//Remove relevant subscription
for subID, sub := range topicData.contentSubs {
if sub.contentFilter.Equals(cfTemp) {
sub.Unsubscribe()
delete(topicData.contentSubs, subID)
}
} 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 len(topicData.contentSubs) == 0 {
pubsubUnsubscribe = true
}

if pubsubUnsubscribe {
err = w.unsubscribeFromPubsubTopic(sub)
err = w.unsubscribeFromPubsubTopic(topicData)
if err != nil {
return err
}
Expand Down

0 comments on commit 8709afb

Please sign in to comment.