fix: avoid wecom message dedupe race in async callback

This commit is contained in:
Jared Mahotiere 2026-02-23 13:23:49 -05:00
parent a37b3ba3ff
commit 8da7f08a90

View file

@ -37,7 +37,7 @@ type WeComBotChannel struct {
ctx context.Context
cancel context.CancelFunc
processedMsgs map[string]bool // Message deduplication: msg_id -> processed
msgMu sync.RWMutex
msgMu *sync.RWMutex
}
// WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT)
@ -102,6 +102,7 @@ func NewWeComBotChannel(cfg config.WeComConfig, messageBus *bus.MessageBus) (*We
BaseChannel: base,
config: cfg,
processedMsgs: make(map[string]bool),
msgMu: &sync.RWMutex{},
}, nil
}
@ -330,6 +331,12 @@ func (c *WeComBotChannel) processMessage(ctx context.Context, msg WeComBotMessag
// Message deduplication: Use msg_id to prevent duplicate processing
msgID := msg.MsgID
if c.msgMu == nil {
c.msgMu = &sync.RWMutex{}
}
if c.processedMsgs == nil {
c.processedMsgs = make(map[string]bool)
}
c.msgMu.Lock()
if c.processedMsgs[msgID] {
c.msgMu.Unlock()