mirror of https://github.com/status-im/go-waku.git
fix: data race in filter unsubscribe
This commit is contained in:
parent
22398b2868
commit
20040f2e9b
|
@ -407,11 +407,14 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte
|
|||
|
||||
localWg := sync.WaitGroup{}
|
||||
resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items))
|
||||
var peersUnsubscribed []peer.ID
|
||||
|
||||
for peerID := range wf.subscriptions.items {
|
||||
if params.selectedPeer != "" && peerID != params.selectedPeer {
|
||||
continue
|
||||
}
|
||||
peersUnsubscribed = append(peersUnsubscribed, peerID)
|
||||
|
||||
localWg.Add(1)
|
||||
go func(peerID peer.ID) {
|
||||
defer localWg.Done()
|
||||
|
@ -423,9 +426,6 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte
|
|||
if err != nil {
|
||||
wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err))
|
||||
}
|
||||
|
||||
delete(wf.subscriptions.items, peerID)
|
||||
|
||||
resultChan <- WakuFilterPushResult{
|
||||
Err: err,
|
||||
PeerID: peerID,
|
||||
|
@ -435,6 +435,10 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte
|
|||
|
||||
localWg.Wait()
|
||||
close(resultChan)
|
||||
|
||||
for _, peerID := range peersUnsubscribed {
|
||||
if len(wf.subscriptions.items[peerID].subscriptionsPerTopic) == 0 {
|
||||
delete(wf.subscriptions.items, peerID)
|
||||
}
|
||||
}
|
||||
return resultChan, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue