From f29b5ec87f981bed11d43028ada84fa5d36e35d2 Mon Sep 17 00:00:00 2001 From: ppom <> Date: Sun, 24 Sep 2023 17:28:37 +0200 Subject: [PATCH] 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 --- app/daemon.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/daemon.go b/app/daemon.go index c64c600..48fb50c 100644 --- a/app/daemon.go +++ b/app/daemon.go @@ -186,14 +186,19 @@ func matchesManagerHandleMatch(pft PFT) bool { if matches[pf] == nil { 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 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 {