fix: avoid wecom message dedupe race in async callback
This commit is contained in:
parent
a37b3ba3ff
commit
8da7f08a90
1 changed files with 8 additions and 1 deletions
|
|
@ -37,7 +37,7 @@ type WeComBotChannel struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
processedMsgs map[string]bool // Message deduplication: msg_id -> processed
|
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)
|
// 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,
|
BaseChannel: base,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
processedMsgs: make(map[string]bool),
|
processedMsgs: make(map[string]bool),
|
||||||
|
msgMu: &sync.RWMutex{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,6 +331,12 @@ func (c *WeComBotChannel) processMessage(ctx context.Context, msg WeComBotMessag
|
||||||
|
|
||||||
// Message deduplication: Use msg_id to prevent duplicate processing
|
// Message deduplication: Use msg_id to prevent duplicate processing
|
||||||
msgID := msg.MsgID
|
msgID := msg.MsgID
|
||||||
|
if c.msgMu == nil {
|
||||||
|
c.msgMu = &sync.RWMutex{}
|
||||||
|
}
|
||||||
|
if c.processedMsgs == nil {
|
||||||
|
c.processedMsgs = make(map[string]bool)
|
||||||
|
}
|
||||||
c.msgMu.Lock()
|
c.msgMu.Lock()
|
||||||
if c.processedMsgs[msgID] {
|
if c.processedMsgs[msgID] {
|
||||||
c.msgMu.Unlock()
|
c.msgMu.Unlock()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue