From 4c3ec60da56f3466c686b284398e2c0da2766d1c Mon Sep 17 00:00:00 2001 From: Igor Sirotin Date: Fri, 23 Aug 2024 15:23:07 +0100 Subject: [PATCH] fix: prevent panics in peermanager and WakuRelay (#1206) --- waku/v2/peermanager/peer_manager.go | 4 ++++ waku/v2/protocol/relay/waku_relay.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index e12d3b24..2ac489a0 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -125,6 +125,10 @@ func inAndOutRelayPeers(relayPeers int) (int, int) { // checkAndUpdateTopicHealth finds health of specified topic and updates and notifies of the same. // Also returns the healthyPeerCount func (pm *PeerManager) checkAndUpdateTopicHealth(topic *NodeTopicDetails) int { + if topic == nil { + return 0 + } + healthyPeerCount := 0 for _, p := range pm.relay.PubSub().MeshPeers(topic.topic.String()) { diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index 05fc823d..936b37c5 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -493,6 +493,9 @@ func (w *WakuRelay) Unsubscribe(ctx context.Context, contentFilter waku_proto.Co // unsubscribeFromPubsubTopic unsubscribes subscription from underlying pubsub. // Note: caller has to acquire topicsMutex in order to avoid race conditions func (w *WakuRelay) unsubscribeFromPubsubTopic(topicData *pubsubTopicSubscriptionDetails) error { + if topicData.subscription == nil { + return nil + } pubSubTopic := topicData.subscription.Topic() w.log.Info("unsubscribing from pubsubTopic", zap.String("topic", pubSubTopic))