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
e53cbd96
authored
Sep 03, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(channel): implement per-channel locking to ensure thread-safe updates in multi-key mode
parent
4f5c3437
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
0 deletions
+8
-0
model/channel.go
+8
-0
No files found.
model/channel.go
View file @
e53cbd96
...
@@ -607,8 +607,12 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
...
@@ -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
...
@@ -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
}
}
...
...
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