mirror of https://github.com/status-im/go-waku.git
fix: flaky panic on relay unsubscribe (#1201)
This commit is contained in:
parent
8ff8779bb0
commit
1472b17d39
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue