From 67b45455b81940f5c6ca9b74e27ca77224e1b47b Mon Sep 17 00:00:00 2001 From: binwiederhier Date: Mon, 20 Feb 2023 21:46:25 -0500 Subject: [PATCH] Do not panic when changing tiers, and user is nil --- server/visitor.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/visitor.go b/server/visitor.go index 04bd822..b96563d 100644 --- a/server/visitor.go +++ b/server/visitor.go @@ -330,9 +330,13 @@ func (v *visitor) SetUser(u *user.User) { v.mu.Lock() defer v.mu.Unlock() shouldResetLimiters := v.user.TierID() != u.TierID() // TierID works with nil receiver - v.user = u + v.user = u // u may be nil! if shouldResetLimiters { - v.resetLimitersNoLock(u.Stats.Messages, u.Stats.Emails, true) + var messages, emails int64 + if u != nil { + messages, emails = u.Stats.Messages, u.Stats.Emails + } + v.resetLimitersNoLock(messages, emails, true) } }