From bc3d897d7a315153f9dcdbf742435551abbeda4e Mon Sep 17 00:00:00 2001 From: Karmanyaah Malhotra Date: Tue, 21 Feb 2023 20:16:03 -0600 Subject: [PATCH] Use mutexes in topic --- server/topic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/topic.go b/server/topic.go index 19501a87..b168c70f 100644 --- a/server/topic.go +++ b/server/topic.go @@ -58,6 +58,8 @@ func (t *topic) Subscribe(s subscriber, visitor *visitor, cancel func(), subscri } func (t *topic) Stale() bool { + t.mu.Lock() + defer t.mu.Unlock() // if Time is initialized (not the zero value) and the expiry time has passed if !t.lastVisitorExpires.IsZero() && t.lastVisitorExpires.Before(time.Now()) { t.lastVisitor = nil @@ -66,6 +68,8 @@ func (t *topic) Stale() bool { } func (t *topic) Billee() *visitor { + t.mu.Lock() + defer t.mu.Unlock() return t.lastVisitor }