From 5f19eef945dc30d860d5c17924127eef29953398 Mon Sep 17 00:00:00 2001 From: Jan S Date: Mon, 5 Jan 2026 17:41:39 +0100 Subject: [PATCH] fix: OpenBSD does not support TCPKeepalive intervals (#1382) Signed-off-by: houseme Co-authored-by: houseme Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- crates/utils/src/sys/user_agent.rs | 1 + rustfs/src/server/http.rs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/utils/src/sys/user_agent.rs b/crates/utils/src/sys/user_agent.rs index 20eee81a..28486e89 100644 --- a/crates/utils/src/sys/user_agent.rs +++ b/crates/utils/src/sys/user_agent.rs @@ -15,6 +15,7 @@ use rustfs_config::VERSION; use std::env; use std::fmt; +#[cfg(not(any(target_os = "openbsd", target_os = "freebsd")))] use sysinfo::System; /// Business Type Enumeration diff --git a/rustfs/src/server/http.rs b/rustfs/src/server/http.rs index c698ce4b..3f3473b7 100644 --- a/rustfs/src/server/http.rs +++ b/rustfs/src/server/http.rs @@ -30,7 +30,10 @@ use hyper_util::{ }; use metrics::{counter, histogram}; use rustfs_common::GlobalReadiness; +#[cfg(not(target_os = "openbsd"))] use rustfs_config::{MI_B, RUSTFS_TLS_CERT, RUSTFS_TLS_KEY}; +#[cfg(target_os = "openbsd")] +use rustfs_config::{RUSTFS_TLS_CERT, RUSTFS_TLS_KEY}; use rustfs_ecstore::rpc::{TONIC_RPC_PREFIX, verify_rpc_signature}; use rustfs_protos::proto_gen::node_service::node_service_server::NodeServiceServer; use rustfs_utils::net::parse_and_resolve_address; @@ -375,12 +378,20 @@ pub async fn start_http_server( // Enable TCP Keepalive to detect dead clients (e.g. power loss) // Idle: 10s, Interval: 5s, Retries: 3 - let ka = TcpKeepalive::new() - .with_time(Duration::from_secs(10)) - .with_interval(Duration::from_secs(5)); + let ka = { + #[cfg(not(target_os = "openbsd"))] + let ka = TcpKeepalive::new() + .with_time(Duration::from_secs(10)) + .with_interval(Duration::from_secs(5)) + .with_retries(3); - #[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))] - let ka = ka.with_retries(3); + // On OpenBSD socket2 only supports configuring the initial + // TCP keepalive timeout; intervals and retries cannot be set. + #[cfg(target_os = "openbsd")] + let ka = TcpKeepalive::new().with_time(Duration::from_secs(10)); + + ka + }; if let Err(err) = socket_ref.set_tcp_keepalive(&ka) { warn!(?err, "Failed to set TCP_KEEPALIVE"); @@ -389,9 +400,11 @@ pub async fn start_http_server( if let Err(err) = socket_ref.set_tcp_nodelay(true) { warn!(?err, "Failed to set TCP_NODELAY"); } + #[cfg(not(any(target_os = "openbsd")))] if let Err(err) = socket_ref.set_recv_buffer_size(4 * MI_B) { warn!(?err, "Failed to set set_recv_buffer_size"); } + #[cfg(not(any(target_os = "openbsd")))] if let Err(err) = socket_ref.set_send_buffer_size(4 * MI_B) { warn!(?err, "Failed to set set_send_buffer_size"); }