From 8bf9878b4dea610069c72a9af36de0ed1c936dd1 Mon Sep 17 00:00:00 2001 From: Alex Vanderpot Date: Wed, 8 Mar 2023 16:52:24 -0800 Subject: [PATCH] fix concurrent map access --- pkg/fedfx/module.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/fedfx/module.go b/pkg/fedfx/module.go index 5482f57..42b951e 100644 --- a/pkg/fedfx/module.go +++ b/pkg/fedfx/module.go @@ -3,6 +3,7 @@ package fedfx import ( "fmt" "strings" + "sync" "github.com/bwmarrin/discordgo" "go.uber.org/config" @@ -40,6 +41,7 @@ type fedLogger struct { config Config messageStore messagefx.Store lastSong map[string]string + lastSongLock sync.Mutex } func New(p Params) error { @@ -126,13 +128,16 @@ func (p *fedLogger) handlePresenceUpdate(s *discordgo.Session, m *discordgo.Pres return } + p.lastSongLock.Lock() if lastSong, ok := p.lastSong[m.User.ID]; ok { if songName == lastSong { p.Log.Debug("duplicate spotify presence") + p.lastSongLock.Unlock() return } } p.lastSong[m.User.ID] = songName + p.lastSongLock.Unlock() u, err := s.State.Member(m.GuildID, m.User.ID) if err != nil {