From e433e7d470b27b8d3b1fab2736056b006cdc7d1b Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Tue, 26 Jan 2021 16:56:06 +0100 Subject: [PATCH] Fix potential race condition --- waku/waku.go | 2 +- whisper/whisper.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/waku/waku.go b/waku/waku.go index b94b94df6..6fce25e46 100644 --- a/waku/waku.go +++ b/waku/waku.go @@ -595,9 +595,9 @@ func (w *Waku) notifyPeersAboutTopicInterestChange(topicInterest []common.TopicT } func (w *Waku) getPeers() []common.Peer { + w.peerMu.Lock() arr := make([]common.Peer, len(w.peers)) i := 0 - w.peerMu.Lock() for p := range w.peers { arr[i] = p i++ diff --git a/whisper/whisper.go b/whisper/whisper.go index a3efd65cb..6967bad7c 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -459,9 +459,9 @@ func (whisper *Whisper) notifyPeersAboutBloomFilterChange(bloom []byte) { } func (whisper *Whisper) getPeers() []*Peer { + whisper.peerMu.Lock() arr := make([]*Peer, len(whisper.peers)) i := 0 - whisper.peerMu.Lock() for p := range whisper.peers { arr[i] = p i++