fix: use dual-stack binding and proper error handling for IPv6 sockets#151
Draft
englishm-cloudflare wants to merge 1 commit intocloudflare:mainfrom
Draft
fix: use dual-stack binding and proper error handling for IPv6 sockets#151englishm-cloudflare wants to merge 1 commit intocloudflare:mainfrom
englishm-cloudflare wants to merge 1 commit intocloudflare:mainfrom
Conversation
Replace the default [::]:0 bind behavior with socket2-based binding that explicitly sets IPV6_V6ONLY=false for cross-platform dual-stack support. On macOS/Windows, IPv6 sockets are IPv6-only by default, causing connection failures when targeting IPv4-only hosts. Changes: - Add bind_smart() using socket2 to request dual-stack on IPv6 sockets - Config::new() now returns Result instead of panicking on bind failure - Args::load() falls back to 0.0.0.0:port with a warning if IPv6 fails - Track actual dual-stack state at bind time instead of using compile-time cfg!(target_os = "linux") assumption - Thread is_dual_stack through Config -> Endpoint -> Client for accurate address_family() detection at connect time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[::]:0bind withsocket2-based binding that explicitly setsIPV6_V6ONLY=false, enabling cross-platform dual-stack (IPv4 + IPv6) support on a single socket.Config::new()now returnsResultinstead of panicking on bind failure.Args::load()falls back to0.0.0.0:portwith a warning if IPv6 binding fails.cfg!(target_os = "linux")assumption) and threadis_dual_stackthroughConfig→Endpoint→Clientsoaddress_family()detection is accurate at connect time.Motivation
On macOS and Windows, IPv6 sockets default to
IPV6_V6ONLY=true, which means binding to[::]only accepts IPv6 connections. When a client on one of these platforms tries to connect to an IPv4-only host, the connection silently fails. Linux happens to default to dual-stack, so this went unnoticed there.This change makes the behavior consistent across platforms by explicitly requesting dual-stack mode, with a graceful fallback to IPv4-only when the OS or network doesn't support it.