fix: rockmq race condition (#40482)

fix #40481

Signed-off-by: xiaofanluan <xiaofan.luan@zilliz.com>
This commit is contained in:
Xiaofan 2025-03-10 10:54:04 +08:00 committed by GitHub
parent d6a650bd14
commit 1c9d43ee9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -612,9 +612,16 @@ func (rmq *rocksmq) destroyConsumerGroupInternal(topicName, groupName string) er
consumers := vals.([]*Consumer) consumers := vals.([]*Consumer)
for index, v := range consumers { for index, v := range consumers {
if v.GroupName == groupName { if v.GroupName == groupName {
// Fix data race: close the channel before modifying the slice
close(v.MsgMutex) close(v.MsgMutex)
consumers = append(consumers[:index], consumers[index+1:]...)
rmq.consumers.Store(topicName, consumers) // Create a new slice to avoid data race
newConsumers := make([]*Consumer, 0, len(consumers)-1)
newConsumers = append(newConsumers, consumers[:index]...)
if index < len(consumers)-1 {
newConsumers = append(newConsumers, consumers[index+1:]...)
}
rmq.consumers.Store(topicName, newConsumers)
break break
} }
} }