mirror of https://github.com/status-im/go-waku.git
fix: handle duplicate filter id removal
This commit is contained in:
parent
231469b441
commit
46500b0de9
|
@ -49,6 +49,11 @@ func (fm *FilterMap) Delete(key string) {
|
||||||
fm.Lock()
|
fm.Lock()
|
||||||
defer fm.Unlock()
|
defer fm.Unlock()
|
||||||
|
|
||||||
|
_, ok := fm.items[key]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
close(fm.items[key].Chan)
|
close(fm.items[key].Chan)
|
||||||
delete(fm.items, key)
|
delete(fm.items, key)
|
||||||
}
|
}
|
||||||
|
|
|
@ -440,7 +440,7 @@ func (wf *WakuFilter) UnsubscribeFilterByID(ctx context.Context, filterID string
|
||||||
// the contentTopics are removed the subscription is dropped completely
|
// the contentTopics are removed the subscription is dropped completely
|
||||||
func (wf *WakuFilter) UnsubscribeFilter(ctx context.Context, cf ContentFilter) error {
|
func (wf *WakuFilter) UnsubscribeFilter(ctx context.Context, cf ContentFilter) error {
|
||||||
// Remove local filter
|
// Remove local filter
|
||||||
var idsToRemove []string
|
idsToRemove := make(map[string]struct{})
|
||||||
for filterMapItem := range wf.filters.Items() {
|
for filterMapItem := range wf.filters.Items() {
|
||||||
f := filterMapItem.Value
|
f := filterMapItem.Value
|
||||||
id := filterMapItem.Key
|
id := filterMapItem.Key
|
||||||
|
@ -469,12 +469,12 @@ func (wf *WakuFilter) UnsubscribeFilter(ctx context.Context, cf ContentFilter) e
|
||||||
|
|
||||||
}
|
}
|
||||||
if len(f.ContentFilters) == 0 {
|
if len(f.ContentFilters) == 0 {
|
||||||
idsToRemove = append(idsToRemove, id)
|
idsToRemove[id] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rId := range idsToRemove {
|
for rId := range idsToRemove {
|
||||||
wf.filters.Delete(rId)
|
wf.filters.Delete(rId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue