From 36e9aa49f7aa536d9b04189a5f07d22581a73aac Mon Sep 17 00:00:00 2001 From: Adora Laura Kalb Date: Fri, 19 Apr 2024 11:09:06 +0200 Subject: [PATCH] fix deadlock with waiting mutex --- cache/cache.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cache/cache.go b/cache/cache.go index 96cde8b..6d0b9bd 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -69,12 +69,13 @@ func (sc *ScoreCache) Add(score float64, ip netip.Addr, ts time.Time) { func (lc *ScoreCache) Get(ip netip.Addr) (ServerScore, error) { now := time.Now() lc.mu.RLock() - defer lc.mu.RUnlock() cachedScore, ok := lc.scores[ip] if !ok { + lc.mu.RUnlock() return ServerScore{}, newCacheMissError() } + lc.mu.RUnlock() if now.After(cachedScore.expiresAt) { lc.delete(ip)