Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
c3faf2d6
Unverified
Commit
c3faf2d6
authored
Sep 24, 2025
by
luna
Committed by
GitHub
Sep 24, 2025
Browse files
[router] select first healthy worker on proxied get requests (#10827)
parent
9209b209
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
sgl-router/src/routers/http/router.rs
sgl-router/src/routers/http/router.rs
+22
-2
No files found.
sgl-router/src/routers/http/router.rs
View file @
c3faf2d6
...
...
@@ -103,10 +103,11 @@ impl Router {
fn
select_first_worker
(
&
self
)
->
Result
<
String
,
String
>
{
let
workers
=
self
.worker_registry
.get_all
();
if
workers
.is_empty
()
{
let
healthy_workers
:
Vec
<
_
>
=
workers
.iter
()
.filter
(|
w
|
w
.is_healthy
())
.collect
();
if
healthy_workers
.is_empty
()
{
Err
(
"No workers are available"
.to_string
())
}
else
{
Ok
(
workers
[
0
]
.url
()
.to_string
())
Ok
(
healthy_
workers
[
0
]
.url
()
.to_string
())
}
}
...
...
@@ -1119,6 +1120,13 @@ mod tests {
}
}
fn
create_test_unhealthy_router
()
->
Router
{
let
router
=
create_test_regular_router
();
let
workers
=
router
.worker_registry
.get_all
();
workers
[
0
]
.set_healthy
(
false
);
router
}
#[test]
fn
test_router_get_worker_urls_regular
()
{
let
router
=
create_test_regular_router
();
...
...
@@ -1140,4 +1148,16 @@ mod tests {
// DashMap doesn't guarantee order, so just check we get one of the workers
assert
!
(
url
==
"http://worker1:8080"
||
url
==
"http://worker2:8080"
);
}
#[test]
fn
test_select_first_worker_with_unhealthy_worker
()
{
let
router
=
create_test_unhealthy_router
();
let
result
=
router
.select_first_worker
();
assert
!
(
result
.is_ok
());
let
url
=
result
.unwrap
();
let
worker
=
router
.worker_registry
.get_by_url
(
&
url
)
.unwrap
();
assert
!
(
worker
.is_healthy
());
}
}
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