From 1c91e8e3e1e75bc424ba7145e54f181c2713fb39 Mon Sep 17 00:00:00 2001 From: Han Xu Date: Sat, 7 Feb 2026 14:35:25 -0800 Subject: [PATCH 1/3] fix: invert reuseport feature --- Cargo.toml | 4 ++-- src/service_daemon.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 28476214..8091235a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ categories = ["network-programming"] description = "mDNS Service Discovery library with no async runtime dependency" [features] -reuseport = [] +no_reuseport = [] async = ["flume/async"] logging = ["log"] -default = ["reuseport", "async", "logging"] +default = ["async", "logging"] [dependencies] fastrand = "2.3" diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 0e10c1a1..0dcf6c75 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -741,7 +741,7 @@ fn new_socket(addr: SocketAddr, non_block: bool) -> Result { fd.set_reuse_address(true) .map_err(|e| e_fmt!("set ReuseAddr failed: {}", e))?; - #[cfg(all(unix, feature = "reuseport"))] // this is currently restricted to Unix's in socket2 + #[cfg(all(unix, not(feature = "no_reuseport")))] fd.set_reuse_port(true) .map_err(|e| e_fmt!("set ReusePort failed: {}", e))?; From 8e801b0a38e5563ebb2b9066fbfa1148ac82228c Mon Sep 17 00:00:00 2001 From: Han Xu Date: Sun, 8 Feb 2026 10:38:57 -0800 Subject: [PATCH 2/3] add a comment --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 8091235a..7742bf8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ categories = ["network-programming"] description = "mDNS Service Discovery library with no async runtime dependency" [features] +# Disable SO_REUSEPORT socket option for older Linux kernels (before v3.9) that don't support it. no_reuseport = [] async = ["flume/async"] logging = ["log"] From 72b17202c2c4f6d55af879fd2ebe4d2e49ed9c4d Mon Sep 17 00:00:00 2001 From: Han Xu Date: Sun, 8 Feb 2026 14:08:08 -0800 Subject: [PATCH 3/3] log the reuseport error and move on --- Cargo.toml | 2 -- src/service_daemon.rs | 10 +++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7742bf8e..37e61664 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,6 @@ categories = ["network-programming"] description = "mDNS Service Discovery library with no async runtime dependency" [features] -# Disable SO_REUSEPORT socket option for older Linux kernels (before v3.9) that don't support it. -no_reuseport = [] async = ["flume/async"] logging = ["log"] default = ["async", "logging"] diff --git a/src/service_daemon.rs b/src/service_daemon.rs index 0dcf6c75..34600c04 100644 --- a/src/service_daemon.rs +++ b/src/service_daemon.rs @@ -741,9 +741,13 @@ fn new_socket(addr: SocketAddr, non_block: bool) -> Result { fd.set_reuse_address(true) .map_err(|e| e_fmt!("set ReuseAddr failed: {}", e))?; - #[cfg(all(unix, not(feature = "no_reuseport")))] - fd.set_reuse_port(true) - .map_err(|e| e_fmt!("set ReusePort failed: {}", e))?; + #[cfg(unix)] + if let Err(e) = fd.set_reuse_port(true) { + debug!( + "SO_REUSEPORT is not supported, continuing without it: {}", + e + ); + } if non_block { fd.set_nonblocking(true)