diff options
| author | William Hergès <william@herges.fr> | 2025-12-27 17:59:11 +0100 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-12-27 17:59:11 +0100 |
| commit | 7223c1172448b1a9b2bd8079b56cc84858be2ffc (patch) | |
| tree | 312b63640ca423fa57a234598d2a0c338e67e5bd /backend/admin.go | |
| parent | 563494cb7779a840bd650f0cf215b6e6ae7080ed (diff) | |
fix(backend): memory leak in timeouts
Diffstat (limited to 'backend/admin.go')
| -rw-r--r-- | backend/admin.go | 17 |
1 files 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) { |
