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
755acc61
authored
Aug 04, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: implement channel-specific locking for thread-safe polling
parent
5e47da1a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
controller/channel.go
+4
-0
model/channel.go
+3
-3
No files found.
controller/channel.go
View file @
755acc61
...
...
@@ -1107,6 +1107,10 @@ func ManageMultiKeys(c *gin.Context) {
return
}
lock
:=
model
.
GetChannelPollingLock
(
channel
.
Id
)
lock
.
Lock
()
defer
lock
.
Unlock
()
switch
request
.
Action
{
case
"get_key_status"
:
keys
:=
channel
.
GetKeys
()
...
...
model/channel.go
View file @
755acc61
...
...
@@ -141,7 +141,7 @@ func (channel *Channel) GetNextEnabledKey() (string, int, *types.NewAPIError) {
return
keys
[
selectedIdx
],
selectedIdx
,
nil
case
constant
.
MultiKeyModePolling
:
// Use channel-specific lock to ensure thread-safe polling
lock
:=
g
etChannelPollingLock
(
channel
.
Id
)
lock
:=
G
etChannelPollingLock
(
channel
.
Id
)
lock
.
Lock
()
defer
lock
.
Unlock
()
...
...
@@ -500,8 +500,8 @@ var channelStatusLock sync.Mutex
// channelPollingLocks stores locks for each channel.id to ensure thread-safe polling
var
channelPollingLocks
sync
.
Map
//
g
etChannelPollingLock returns or creates a mutex for the given channel ID
func
g
etChannelPollingLock
(
channelId
int
)
*
sync
.
Mutex
{
//
G
etChannelPollingLock returns or creates a mutex for the given channel ID
func
G
etChannelPollingLock
(
channelId
int
)
*
sync
.
Mutex
{
if
lock
,
exists
:=
channelPollingLocks
.
Load
(
channelId
);
exists
{
return
lock
.
(
*
sync
.
Mutex
)
}
...
...
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