From bbf261ae4a9deaaacd6f570fc92cee23fd9a4342 Mon Sep 17 00:00:00 2001 From: Simo Lin Date: Thu, 4 Sep 2025 00:36:16 -0400 Subject: [PATCH] [router] fix grpc connection mode detection (#9999) --- sgl-router/src/core/worker.rs | 2 +- sgl-router/src/lib.rs | 16 ++-------------- sgl-router/src/main.rs | 16 ++-------------- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/sgl-router/src/core/worker.rs b/sgl-router/src/core/worker.rs index 51c3cdd65..f25fc6eea 100644 --- a/sgl-router/src/core/worker.rs +++ b/sgl-router/src/core/worker.rs @@ -986,7 +986,7 @@ pub fn start_health_checker( // Periodically reset load counters to prevent drift // Only do this when we believe all workers should be idle - if check_count % LOAD_RESET_INTERVAL == 0 { + if check_count.is_multiple_of(LOAD_RESET_INTERVAL) { let max_load = workers_to_check.iter().map(|w| w.load()).max().unwrap_or(0); // Only reset if load appears to be very low (likely drift) if max_load <= 2 { diff --git a/sgl-router/src/lib.rs b/sgl-router/src/lib.rs index 955185e07..938a1ba0c 100644 --- a/sgl-router/src/lib.rs +++ b/sgl-router/src/lib.rs @@ -101,25 +101,13 @@ struct Router { impl Router { /// Determine connection mode from worker URLs fn determine_connection_mode(worker_urls: &[String]) -> config::ConnectionMode { - // Check if any URL is a gRPC endpoint (starts with grpc:// or has port that commonly indicates gRPC) + // Only consider it gRPC if explicitly specified with grpc:// or grpcs:// scheme for url in worker_urls { if url.starts_with("grpc://") || url.starts_with("grpcs://") { return config::ConnectionMode::Grpc; } - // Also check for common gRPC ports if the scheme isn't specified - if let Ok(parsed_url) = url::Url::parse(url) { - if let Some(port) = parsed_url.port() { - // Common gRPC ports - if port == 50051 || port == 9090 || ((50000..=50100).contains(&port)) { - return config::ConnectionMode::Grpc; - } - } - } else if url.contains(":50051") || url.contains(":9090") || url.contains(":5000") { - // Fallback check for URLs that might not parse correctly - return config::ConnectionMode::Grpc; - } } - // Default to HTTP + // Default to HTTP for all other cases (including http://, https://, or no scheme) config::ConnectionMode::Http } diff --git a/sgl-router/src/main.rs b/sgl-router/src/main.rs index c745c0b3b..60986bbea 100644 --- a/sgl-router/src/main.rs +++ b/sgl-router/src/main.rs @@ -286,25 +286,13 @@ struct CliArgs { impl CliArgs { /// Determine connection mode from worker URLs fn determine_connection_mode(worker_urls: &[String]) -> ConnectionMode { - // Check if any URL is a gRPC endpoint (starts with grpc:// or has port that commonly indicates gRPC) + // Only consider it gRPC if explicitly specified with grpc:// or grpcs:// scheme for url in worker_urls { if url.starts_with("grpc://") || url.starts_with("grpcs://") { return ConnectionMode::Grpc; } - // Also check for common gRPC ports if the scheme isn't specified - if let Ok(parsed_url) = url::Url::parse(url) { - if let Some(port) = parsed_url.port() { - // Common gRPC ports - if port == 50051 || port == 9090 || ((50000..=50100).contains(&port)) { - return ConnectionMode::Grpc; - } - } - } else if url.contains(":50051") || url.contains(":9090") || url.contains(":5000") { - // Fallback check for URLs that might not parse correctly - return ConnectionMode::Grpc; - } } - // Default to HTTP + // Default to HTTP for all other cases (including http://, https://, or no scheme) ConnectionMode::Http }