From 7223c1172448b1a9b2bd8079b56cc84858be2ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 27 Dec 2025 17:59:11 +0100 Subject: fix(backend): memory leak in timeouts --- backend/admin.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/admin.go b/backend/admin.go index e5f5696..84b5c0f 100644 --- a/backend/admin.go +++ b/backend/admin.go @@ -56,10 +56,15 @@ func handleTimeout(ctx context.Context) bool { } v.since = time.Now() GetLogger(ctx).Warn("rate limiting IP", "ip", ip, "duration", dur().String()) - go func(v *to) { + go func(v *to, ip string) { time.Sleep(3 * time.Hour) v.n = max(v.n-4, 0) - }(v) + if v.n == 0 { + timeouts.mu.Lock() + defer timeouts.mu.Unlock() + delete(timeouts.tos, ip) + } + }(v, ip) return true } @@ -70,13 +75,7 @@ func resetTimeout(ctx context.Context) { timeouts.mu.Lock() defer timeouts.mu.Unlock() - - v, ok := timeouts.tos[ip] - if !ok { - return - } - v.n = 0 - v.since = time.Unix(0, 0) + delete(timeouts.tos, ip) } func HandleAdmin(r *chi.Mux) { -- cgit v1.2.3