fix: handle duplicate filter id removal

This commit is contained in:
Richard Ramos 2023-05-05 11:06:02 -04:00 committed by RichΛrd
parent 231469b441
commit 46500b0de9
2 changed files with 8 additions and 3 deletions

View File

@ -49,6 +49,11 @@ func (fm *FilterMap) Delete(key string) {
fm.Lock()
defer fm.Unlock()
_, ok := fm.items[key]
if !ok {
return
}
close(fm.items[key].Chan)
delete(fm.items, key)
}

View File

@ -440,7 +440,7 @@ func (wf *WakuFilter) UnsubscribeFilterByID(ctx context.Context, filterID string
// the contentTopics are removed the subscription is dropped completely
func (wf *WakuFilter) UnsubscribeFilter(ctx context.Context, cf ContentFilter) error {
// Remove local filter
var idsToRemove []string
idsToRemove := make(map[string]struct{})
for filterMapItem := range wf.filters.Items() {
f := filterMapItem.Value
id := filterMapItem.Key
@ -469,12 +469,12 @@ func (wf *WakuFilter) UnsubscribeFilter(ctx context.Context, cf ContentFilter) e
}
if len(f.ContentFilters) == 0 {
idsToRemove = append(idsToRemove, id)
idsToRemove[id] = struct{}{}
}
}
}
for _, rId := range idsToRemove {
for rId := range idsToRemove {
wf.filters.Delete(rId)
}