fix(channel): ensure thread-safe polling with channel-specific lock
This commit is contained in:
parent
c7dc4ad1ef
commit
9e4c4d3bd1
@ -112,6 +112,10 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
|
|||||||
return "", 0, types.NewError(errors.New("no keys available"), types.ErrorCodeChannelNoAvailableKey)
|
return "", 0, types.NewError(errors.New("no keys available"), types.ErrorCodeChannelNoAvailableKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock := GetChannelPollingLock(channel.Id)
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
statusList := channel.ChannelInfo.MultiKeyStatusList
|
statusList := channel.ChannelInfo.MultiKeyStatusList
|
||||||
// helper to get key status, default to enabled when missing
|
// helper to get key status, default to enabled when missing
|
||||||
getStatus := func(idx int) int {
|
getStatus := func(idx int) int {
|
||||||
@ -143,9 +147,6 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
|
|||||||
return keys[selectedIdx], selectedIdx, nil
|
return keys[selectedIdx], selectedIdx, nil
|
||||||
case constant.MultiKeyModePolling:
|
case constant.MultiKeyModePolling:
|
||||||
// Use channel-specific lock to ensure thread-safe polling
|
// Use channel-specific lock to ensure thread-safe polling
|
||||||
lock := GetChannelPollingLock(channel.Id)
|
|
||||||
lock.Lock()
|
|
||||||
defer lock.Unlock()
|
|
||||||
|
|
||||||
channelInfo, err := CacheGetChannelInfo(channel.Id)
|
channelInfo, err := CacheGetChannelInfo(channel.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user