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 9c34a1ffd8
commit 7c4e57cf18

View file

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