Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
91caa5b4
Commit
91caa5b4
authored
5 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Fix off by one error in SRV result shuffling
parent
fbb758a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/http/federation/srv_resolver.py
+13
-8
13 additions, 8 deletions
synapse/http/federation/srv_resolver.py
with
13 additions
and
8 deletions
synapse/http/federation/srv_resolver.py
+
13
−
8
View file @
91caa5b4
...
@@ -66,17 +66,18 @@ def _sort_server_list(server_list):
...
@@ -66,17 +66,18 @@ def _sort_server_list(server_list):
for
priority
in
sorted
(
priority_map
):
for
priority
in
sorted
(
priority_map
):
servers
=
priority_map
[
priority
]
servers
=
priority_map
[
priority
]
# This algorithms follows the algorithm described in RFC2782.
# This algorithms roughly follows the algorithm described in RFC2782,
# changed to remove an off-by-one error.
#
#
# N.B. Weights can be zero, which means that you should pick that server
# N.B. Weights can be zero, which means that they should be picked
# last *or* that its the only server in this priority.
# rarely.
# We sort to ensure zero weighted items are first.
servers
.
sort
(
key
=
lambda
s
:
s
.
weight
)
total_weight
=
sum
(
s
.
weight
for
s
in
servers
)
total_weight
=
sum
(
s
.
weight
for
s
in
servers
)
while
servers
:
target_weight
=
random
.
randint
(
0
,
total_weight
)
# Total weight can become zero if there are only zero weight servers
# left, which we handle by just shuffling and appending to the results.
while
servers
and
total_weight
:
target_weight
=
random
.
randint
(
1
,
total_weight
)
for
s
in
servers
:
for
s
in
servers
:
target_weight
-=
s
.
weight
target_weight
-=
s
.
weight
...
@@ -88,6 +89,10 @@ def _sort_server_list(server_list):
...
@@ -88,6 +89,10 @@ def _sort_server_list(server_list):
servers
.
remove
(
s
)
servers
.
remove
(
s
)
total_weight
-=
s
.
weight
total_weight
-=
s
.
weight
if
servers
:
random
.
shuffle
(
servers
)
results
.
extend
(
servers
)
return
results
return
results
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment