Fix bug "expired matches are still present" for "show"

Now matches are deleted at the exact time they expire, not when
accepting a new similar match
This commit is contained in:
ppom 2023-09-24 17:28:37 +02:00
parent d26c7f24f2
commit f29b5ec87f

View File

@ -186,14 +186,19 @@ func matchesManagerHandleMatch(pft PFT) bool {
if matches[pf] == nil { if matches[pf] == nil {
matches[pf] = make(map[time.Time]struct{}) matches[pf] = make(map[time.Time]struct{})
} }
// clean old matches
for old := range matches[pf] {
if !old.Add(filter.retryDuration).After(then) {
delete(matches[pf], old)
}
}
// add new match // add new match
matches[pf][then] = struct{}{} matches[pf][then] = struct{}{}
// remove match when expired
go func(pf PF, then time.Time) {
time.Sleep(filter.retryDuration)
matchesLock.Lock()
if matches[pf] != nil {
// FIXME replace this and all similar occurences
// by clear() when switching to go 1.21
delete(matches[pf], then)
}
matchesLock.Unlock()
}(pf, then)
} }
if filter.Retry <= 1 || len(matches[pf]) >= filter.Retry { if filter.Retry <= 1 || len(matches[pf]) >= filter.Retry {