mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-28 22:58:38 +00:00
fix(channel): implement per-channel locking to ensure thread-safe updates in multi-key mode
This commit is contained in:
@@ -607,8 +607,12 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if channelCache.ChannelInfo.IsMultiKey {
|
if channelCache.ChannelInfo.IsMultiKey {
|
||||||
|
// Use per-channel lock to prevent concurrent map read/write with GetNextEnabledKey
|
||||||
|
pollingLock := GetChannelPollingLock(channelId)
|
||||||
|
pollingLock.Lock()
|
||||||
// 如果是多Key模式,更新缓存中的状态
|
// 如果是多Key模式,更新缓存中的状态
|
||||||
handlerMultiKeyUpdate(channelCache, usingKey, status, reason)
|
handlerMultiKeyUpdate(channelCache, usingKey, status, reason)
|
||||||
|
pollingLock.Unlock()
|
||||||
//CacheUpdateChannel(channelCache)
|
//CacheUpdateChannel(channelCache)
|
||||||
//return true
|
//return true
|
||||||
} else {
|
} else {
|
||||||
@@ -639,7 +643,11 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
|
|||||||
|
|
||||||
if channel.ChannelInfo.IsMultiKey {
|
if channel.ChannelInfo.IsMultiKey {
|
||||||
beforeStatus := channel.Status
|
beforeStatus := channel.Status
|
||||||
|
// Protect map writes with the same per-channel lock used by readers
|
||||||
|
pollingLock := GetChannelPollingLock(channelId)
|
||||||
|
pollingLock.Lock()
|
||||||
handlerMultiKeyUpdate(channel, usingKey, status, reason)
|
handlerMultiKeyUpdate(channel, usingKey, status, reason)
|
||||||
|
pollingLock.Unlock()
|
||||||
if beforeStatus != channel.Status {
|
if beforeStatus != channel.Status {
|
||||||
shouldUpdateAbilities = true
|
shouldUpdateAbilities = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user