fix: data race in WeComBot processedMsgs map access

len(c.processedMsgs) was read outside the lock while another
goroutine could be writing to the map. Move the cleanup check
inside the existing critical section.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dj-oyu 2026-02-24 16:06:04 +09:00
parent 54a63c52a0
commit ddf8617a32

View file

@ -339,14 +339,11 @@ func (c *WeComBotChannel) processMessage(ctx context.Context, msg WeComBotMessag
return return
} }
c.processedMsgs[msgID] = true c.processedMsgs[msgID] = true
c.msgMu.Unlock()
// Clean up old messages periodically (keep last 1000) // Clean up old messages periodically (keep last 1000)
if len(c.processedMsgs) > 1000 { if len(c.processedMsgs) > 1000 {
c.msgMu.Lock()
c.processedMsgs = make(map[string]bool) c.processedMsgs = make(map[string]bool)
c.msgMu.Unlock()
} }
c.msgMu.Unlock()
senderID := msg.From.UserID senderID := msg.From.UserID