Repository navigation
fix: Support IPv6-only environments in IP resolution - #7632
AsadShahid04 wants to merge 2 commits into
Conversation
|
👋 Hi AsadShahid04! Thank you for contributing to ai-dynamo/dynamo. Just a reminder: The 🚀 |
WalkthroughChanges simplify IPv4-to-IPv6 fallback logic in IP resolution by catching all errors from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/runtime/src/pipeline/network/tcp/server.rs (1)
155-177:⚠️ Potential issue | 🔴 CriticalIPv6 addresses cannot bind due to invalid socket address formatting.
This code resolves IPv6 addresses correctly but then converts them to strings and concatenates with the port using
format!("{}:{}", ip, port). For IPv6,IpAddr::to_string()produces unbracketed notation (e.g.,"2001:db8::1"), so the result becomes"2001:db8::1:8080"instead of the required"[2001:db8::1]:8080". TheTcpListener::bind()call at line 326 and socket address parsing at line 61 (tests) will both fail with this format.Fix by either:
- Keeping the
IpAddrtype and constructingSocketAddrdirectly withSocketAddr::new(ip, port), or- Bracketing IPv6 addresses before storing: wrap with
[...]if it's aV6address🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/runtime/src/pipeline/network/tcp/server.rs` around lines 155 - 177, The code converts the resolved IpAddr to a string (.to_string()) and later formats it with the port, which produces invalid unbracketed IPv6 addresses; update the match that computes resolved_ip to return/use the IpAddr (keep the IpAddr value instead of calling .to_string()), and when creating the bind address use SocketAddr::new(ip, port) (or, if you must store a string, detect IpAddr::V6 and wrap it in brackets "[...]" before appending ":port"); change code paths that currently rely on the string (the place that formats "{}:{}", and the TcpListener::bind call) to construct a SocketAddr via SocketAddr::new(ip, port) so IPv6 binds are valid and tests parsing sockets succeed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/runtime/src/pipeline/network/tcp/server.rs`:
- Around line 155-157: The current resolution masks real IPv4 errors by using
or_else and then later matches resolved_ip; change the lookup to call
resolver.local_ip() and if it Err(e) return Err(e) unless e is
LocalIpAddressNotFound, in which case call resolver.local_ipv6() and apply the
same rule (propagate any non-NotFound error); update code referencing
resolved_ip (the variable set from resolver.local_ip()/local_ipv6()) and the
match that previously fell back to loopback to instead correctly propagate
errors. Also fix socket address formatting where IPv6 strings are interpolated
with "{}:{}", replacing those with bracketed IPv6 notation (e.g., "[{}]:{}") or
construct the socket address from an IpAddr so IPv6 addresses become
"[::1]:8080" rather than "::1:8080" (update both occurrences that format the
socket at the places currently using "{}:{}").
In `@lib/runtime/src/utils/ip_resolver.rs`:
- Around line 11-13: Add a regression test that exercises the fallback from IPv4
to IPv6 when the first probe returns an unexpected error: update the
MockIpResolver used in the test suite so it can return distinct errors for
local_ip() and local_ipv6() (instead of normalizing all failures into the same
branch), then write a test that configures the mock to make local_ip() return an
error (non-NotFound) and local_ipv6() return Ok(<some IPv6>), call
resolver.local_ip().or_else(|_| resolver.local_ipv6()) (the code path using
local_ip and local_ipv6), and assert the IPv6 result is used; reference the
MockIpResolver type and the local_ip/local_ipv6 methods when adding the mock
behavior and the new test.
---
Outside diff comments:
In `@lib/runtime/src/pipeline/network/tcp/server.rs`:
- Around line 155-177: The code converts the resolved IpAddr to a string
(.to_string()) and later formats it with the port, which produces invalid
unbracketed IPv6 addresses; update the match that computes resolved_ip to
return/use the IpAddr (keep the IpAddr value instead of calling .to_string()),
and when creating the bind address use SocketAddr::new(ip, port) (or, if you
must store a string, detect IpAddr::V6 and wrap it in brackets "[...]" before
appending ":port"); change code paths that currently rely on the string (the
place that formats "{}:{}", and the TcpListener::bind call) to construct a
SocketAddr via SocketAddr::new(ip, port) so IPv6 binds are valid and tests
parsing sockets succeed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8f540e6d-cd71-4f86-8826-57227bf49bd6
📒 Files selected for processing (2)
lib/runtime/src/pipeline/network/tcp/server.rslib/runtime/src/utils/ip_resolver.rs
b8acfae to
0f9dc8a
Compare
- lib/runtime/src/pipeline/network/tcp/server.rs: Fallback to IPv6 on any local_ip() error, not just LocalIpAddressNotFound - lib/runtime/src/utils/ip_resolver.rs: Same IPv6 fallback pattern Fixes issue where StrategyError from local_ip_address crate was not caught, preventing IPv6 fallback in pure IPv6 environments. Fixes ai-dynamo#7619 Signed-off-by: Asad Shahid <[email protected]>
Refactor IPv6 fallback logic to be more explicit and maintainable: - lib/runtime/src/pipeline/network/tcp/server.rs: Use explicit match pattern instead of or_else for clarity. Falls back to IPv6 on ANY error from IPv4 resolution, then to loopback if both fail. - lib/runtime/src/utils/ip_resolver.rs: Same refactoring for consistency across the codebase. Simplifies error handling by matching on all error cases equally (no special-casing LocalIpAddressNotFound vs StrategyError). This ensures pure IPv6 environments work correctly regardless of which error type local_ip_address returns, and makes the fallback chain explicit: IPv4 -> IPv6 -> 127.0.0.1 Fixes ai-dynamo#7619 Signed-off-by: Asad Shahid <[email protected]>
0f9dc8a to
10f7f41
Compare
|
Hi @AsadShahid04, what's the relationship between #7632 and #7627 - does one supersede the other? Also, can the testing (#7629) be wrapped up into a single PR along with the fix? Ideally there's only 1 PR to fix this instead of 3. |
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
|
This PR has been closed due to inactivity. If you believe this PR is still relevant, please feel free to reopen it with additional context or information. |
Fixes StrategyError handling that prevented IPv6 fallback in pure IPv6 environments.
Fixes #7619
Summary by CodeRabbit