Repository navigation
fix(worker): honor explicit worker connection schemes #1484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,9 +16,21 @@ use crate::{ | |||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| fn explicit_connection_mode(url: &str) -> Option<ConnectionMode> { | ||||||||||||||||||||||||||||||||||||||||||||||
| let normalized_url = url.to_ascii_lowercase(); | ||||||||||||||||||||||||||||||||||||||||||||||
| if normalized_url.starts_with("grpc://") { | ||||||||||||||||||||||||||||||||||||||||||||||
| Some(ConnectionMode::Grpc) | ||||||||||||||||||||||||||||||||||||||||||||||
| } else if normalized_url.starts_with("http://") || normalized_url.starts_with("https://") { | ||||||||||||||||||||||||||||||||||||||||||||||
| Some(ConnectionMode::Http) | ||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| None | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /// Step 1: Detect connection mode (HTTP vs gRPC). | ||||||||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Probes both protocols in parallel. HTTP takes priority if both succeed. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Explicit URL schemes are honored. For bare host:port URLs, probes both | ||||||||||||||||||||||||||||||||||||||||||||||
| /// protocols in parallel and HTTP takes priority if both succeed. | ||||||||||||||||||||||||||||||||||||||||||||||
| /// Does NOT detect backend runtime — that's handled by DetectBackendStep. | ||||||||||||||||||||||||||||||||||||||||||||||
| pub struct DetectConnectionModeStep; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -51,6 +63,37 @@ impl StepExecutor<WorkerWorkflowData> for DetectConnectionModeStep { | |||||||||||||||||||||||||||||||||||||||||||||
| .unwrap_or(app_context.router_config.health_check.timeout_secs); | ||||||||||||||||||||||||||||||||||||||||||||||
| let client = &app_context.client; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(connection_mode) = explicit_connection_mode(&url) { | ||||||||||||||||||||||||||||||||||||||||||||||
| let result = match connection_mode { | ||||||||||||||||||||||||||||||||||||||||||||||
| ConnectionMode::Http => try_http_reachable(&url, timeout, client).await, | ||||||||||||||||||||||||||||||||||||||||||||||
| ConnectionMode::Grpc => try_grpc_reachable(&url, timeout).await, | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+66
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation is susceptible to case-sensitivity issues because the underlying reachability probes perform case-sensitive prefix matching on the URL. To reliably handle schemes and distinguish between different URL types, parse the URL using a dedicated library and check its scheme instead of using string prefix matching. This approach avoids misclassifying URLs and ensures robustness against variations like 'GRPC://'. References
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| match result { | ||||||||||||||||||||||||||||||||||||||||||||||
| Ok(()) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| debug!( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{} explicitly configured as {}", | ||||||||||||||||||||||||||||||||||||||||||||||
| config.url, connection_mode | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| context.data.connection_mode = Some(connection_mode); | ||||||||||||||||||||||||||||||||||||||||||||||
| return Ok(StepResult::Success); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Err(err) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| let protocol = match connection_mode { | ||||||||||||||||||||||||||||||||||||||||||||||
| ConnectionMode::Http => "HTTP", | ||||||||||||||||||||||||||||||||||||||||||||||
| ConnectionMode::Grpc => "gRPC", | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| return Err(WorkflowError::StepFailed { | ||||||||||||||||||||||||||||||||||||||||||||||
| step_id: StepId::new("detect_connection_mode"), | ||||||||||||||||||||||||||||||||||||||||||||||
| message: format!( | ||||||||||||||||||||||||||||||||||||||||||||||
| "{protocol} health check failed for explicit {} worker URL {}: {}", | ||||||||||||||||||||||||||||||||||||||||||||||
| connection_mode, config.url, err | ||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message is redundant, repeating "health check failed" and including both the capitalized
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| let (http_result, grpc_result) = tokio::join!( | ||||||||||||||||||||||||||||||||||||||||||||||
| try_http_reachable(&url, timeout, client), | ||||||||||||||||||||||||||||||||||||||||||||||
| try_grpc_reachable(&url, timeout) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,3 +127,33 @@ impl StepExecutor<WorkerWorkflowData> for DetectConnectionModeStep { | |||||||||||||||||||||||||||||||||||||||||||||
| true | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[cfg(test)] | ||||||||||||||||||||||||||||||||||||||||||||||
| mod tests { | ||||||||||||||||||||||||||||||||||||||||||||||
| use super::*; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn explicit_connection_mode_honors_grpc_scheme() { | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||||||||
| explicit_connection_mode("grpc://localhost:30001"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Some(ConnectionMode::Grpc) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn explicit_connection_mode_honors_http_schemes() { | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||||||||
| explicit_connection_mode("http://localhost:30000"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Some(ConnectionMode::Http) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!( | ||||||||||||||||||||||||||||||||||||||||||||||
| explicit_connection_mode("https://example.com"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Some(ConnectionMode::Http) | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||
| fn explicit_connection_mode_leaves_bare_urls_for_probe_detection() { | ||||||||||||||||||||||||||||||||||||||||||||||
| assert_eq!(explicit_connection_mode("localhost:30000"), None); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Nit:
to_ascii_lowercase()makes detection case-insensitive (e.g.GRPC://hostis recognized), but the original mixed-case URL is then passed unchanged totry_grpc_reachable/try_http_reachable, which use case-sensitivestarts_with("grpc://")/starts_with("https://")internally. For a URL likeGRPC://localhost:30001, detection correctly picks gRPC, buttry_grpc_reachablefalls into itselsebranch and produces a malformedgrpc://GRPC://localhost:30001.Two options:
to_ascii_lowercase()so detection is case-sensitive like downstream (simplest, mixed-case schemes are rare).Either way, the detection and the downstream consumers should agree on case handling.