Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3ef137a8
Commit
3ef137a8
authored
Jun 06, 2024
by
Brad Davidson
Committed by
Brad Davidson
Jun 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix race condition panic in loadbalancer.nextServer
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
12864fb6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
8 deletions
+18
-8
servers.go
pkg/agent/loadbalancer/servers.go
+18
-8
No files found.
pkg/agent/loadbalancer/servers.go
View file @
3ef137a8
...
@@ -115,23 +115,33 @@ func (lb *LoadBalancer) nextServer(failedServer string) (string, error) {
...
@@ -115,23 +115,33 @@ func (lb *LoadBalancer) nextServer(failedServer string) (string, error) {
lb
.
mutex
.
RLock
()
lb
.
mutex
.
RLock
()
defer
lb
.
mutex
.
RUnlock
()
defer
lb
.
mutex
.
RUnlock
()
// note: these fields are not protected by the mutex, so we clamp the index value and update
// the index/current address using local variables, to avoid time-of-check vs time-of-use
// race conditions caused by goroutine A incrementing it in between the time goroutine B
// validates its value, and uses it as a list index.
currentServerAddress
:=
lb
.
currentServerAddress
nextServerIndex
:=
lb
.
nextServerIndex
if
len
(
lb
.
randomServers
)
==
0
{
if
len
(
lb
.
randomServers
)
==
0
{
return
""
,
errors
.
New
(
"No servers in load balancer proxy list"
)
return
""
,
errors
.
New
(
"No servers in load balancer proxy list"
)
}
}
if
len
(
lb
.
randomServers
)
==
1
{
if
len
(
lb
.
randomServers
)
==
1
{
return
lb
.
currentServerAddress
,
nil
return
currentServerAddress
,
nil
}
}
if
failedServer
!=
lb
.
currentServerAddress
{
if
failedServer
!=
currentServerAddress
{
return
lb
.
currentServerAddress
,
nil
return
currentServerAddress
,
nil
}
}
if
lb
.
nextServerIndex
>=
len
(
lb
.
randomServers
)
{
if
nextServerIndex
>=
len
(
lb
.
randomServers
)
{
lb
.
nextServerIndex
=
0
nextServerIndex
=
0
}
}
lb
.
currentServerAddress
=
lb
.
randomServers
[
lb
.
nextServerIndex
]
currentServerAddress
=
lb
.
randomServers
[
nextServerIndex
]
lb
.
nextServerIndex
++
nextServerIndex
++
lb
.
currentServerAddress
=
currentServerAddress
lb
.
nextServerIndex
=
nextServerIndex
return
lb
.
currentServerAddress
,
nil
return
currentServerAddress
,
nil
}
}
// dialContext dials a new connection using the environment's proxy settings, and adds its wrapped connection to the map
// dialContext dials a new connection using the environment's proxy settings, and adds its wrapped connection to the map
...
...
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