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:
parent
54a63c52a0
commit
ddf8617a32
1 changed files with 1 additions and 4 deletions
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue