Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e4c4d3b
authored
Aug 28, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(channel): ensure thread-safe polling with channel-specific lock
parent
c7dc4ad1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
model/channel.go
+4
-3
No files found.
model/channel.go
View file @
9e4c4d3b
...
@@ -112,6 +112,10 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
...
@@ -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) {
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment