fix deadlock with waiting mutex

This commit is contained in:
Adora Laura Kalb 2024-04-19 11:09:06 +02:00
parent c713e16ed2
commit 36e9aa49f7
Signed by: adoralaura
GPG key ID: E2E0F82107536C1B

3
cache/cache.go vendored
View file

@ -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) { func (lc *ScoreCache) Get(ip netip.Addr) (ServerScore, error) {
now := time.Now() now := time.Now()
lc.mu.RLock() lc.mu.RLock()
defer lc.mu.RUnlock()
cachedScore, ok := lc.scores[ip] cachedScore, ok := lc.scores[ip]
if !ok { if !ok {
lc.mu.RUnlock()
return ServerScore{}, newCacheMissError() return ServerScore{}, newCacheMissError()
} }
lc.mu.RUnlock()
if now.After(cachedScore.expiresAt) { if now.After(cachedScore.expiresAt) {
lc.delete(ip) lc.delete(ip)