From 5bb97d220ad711f58f77dd8e3cbc3eb28c40b7b8 Mon Sep 17 00:00:00 2001 From: frank Date: Thu, 12 Dec 2024 18:30:36 +0800 Subject: [PATCH] fix: concurrent peerMap iteration and write --- waku/v2/peermanager/peer_selection.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/waku/v2/peermanager/peer_selection.go b/waku/v2/peermanager/peer_selection.go index 2d477728c..1fa5a90ae 100644 --- a/waku/v2/peermanager/peer_selection.go +++ b/waku/v2/peermanager/peer_selection.go @@ -130,6 +130,7 @@ func (pm *PeerManager) selectServicePeer(criteria PeerSelectionCriteria) (PeerSe if len(criteria.PubsubTopics) == 0 || (len(criteria.PubsubTopics) == 1 && criteria.PubsubTopics[0] == "") { return slot.getRandom(criteria.MaxPeers, criteria.ExcludePeers) } else { //PubsubTopic based selection + slot.mu.RLock() keys := make([]peer.ID, 0, len(slot.m)) for i := range slot.m { if PeerInSet(criteria.ExcludePeers, i) { @@ -137,6 +138,7 @@ func (pm *PeerManager) selectServicePeer(criteria PeerSelectionCriteria) (PeerSe } keys = append(keys, i) } + slot.mu.RUnlock() selectedPeers := pm.host.Peerstore().(wps.WakuPeerstore).PeersByPubSubTopics(criteria.PubsubTopics, keys...) tmpPeers, err := selectRandomPeers(selectedPeers, criteria.ExcludePeers, criteria.MaxPeers) for tmpPeer := range tmpPeers {