From 8da7f08a905f92033ed72acda55d4fcbdb351d4c Mon Sep 17 00:00:00 2001 From: Jared Mahotiere Date: Mon, 23 Feb 2026 13:23:49 -0500 Subject: [PATCH] fix: avoid wecom message dedupe race in async callback --- pkg/channels/wecom.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/channels/wecom.go b/pkg/channels/wecom.go index 863efd79a..b3edbcf44 100644 --- a/pkg/channels/wecom.go +++ b/pkg/channels/wecom.go @@ -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()