From 3c9565d351e2938a777b992b1057c58758c0f8ff Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 13:24:30 -0500 Subject: [PATCH] Add support for tcp_user_timeout (#503) * Add support for tcp_user_timeout * option * duration * Some() * docs * fmt, compile --- CONFIG.md | 8 +++++++- src/config.rs | 7 +++++++ src/messages.rs | 9 ++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index 7a1a867..3118a49 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -151,7 +151,13 @@ path: general.tcp_keepalives_interval default: 5 ``` -Number of seconds between keepalive packets. +### tcp_user_timeout +``` +path: general.tcp_user_timeout +default: 10000 +``` +A linux-only parameters that defines the amount of time in milliseconds that transmitted data may remain unacknowledged or buffered data may remain untransmitted (due to zero window size) before TCP will forcibly disconnect + ### tls_certificate ``` diff --git a/src/config.rs b/src/config.rs index ea5a8bf..9228b9b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -261,6 +261,8 @@ pub struct General { pub tcp_keepalives_count: u32, #[serde(default = "General::default_tcp_keepalives_interval")] pub tcp_keepalives_interval: u64, + #[serde(default = "General::default_tcp_user_timeout")] + pub tcp_user_timeout: u64, #[serde(default)] // False pub log_client_connections: bool, @@ -360,6 +362,10 @@ impl General { 5 // 5 seconds } + pub fn default_tcp_user_timeout() -> u64 { + 10000 // 10000 milliseconds + } + pub fn default_idle_timeout() -> u64 { 600000 // 10 minutes } @@ -427,6 +433,7 @@ impl Default for General { tcp_keepalives_idle: Self::default_tcp_keepalives_idle(), tcp_keepalives_count: Self::default_tcp_keepalives_count(), tcp_keepalives_interval: Self::default_tcp_keepalives_interval(), + tcp_user_timeout: Self::default_tcp_user_timeout(), log_client_connections: false, log_client_disconnections: false, autoreload: None, diff --git a/src/messages.rs b/src/messages.rs index 1f49465..eb0ea73 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -669,6 +669,13 @@ pub fn configure_socket(stream: &TcpStream) { let sock_ref = SockRef::from(stream); let conf = get_config(); + #[cfg(target_os = "linux")] + match sock_ref.set_tcp_user_timeout(Some(Duration::from_millis(conf.general.tcp_user_timeout))) + { + Ok(_) => (), + Err(err) => error!("Could not configure tcp_user_timeout for socket: {}", err), + } + match sock_ref.set_keepalive(true) { Ok(_) => { match sock_ref.set_tcp_keepalive( @@ -678,7 +685,7 @@ pub fn configure_socket(stream: &TcpStream) { .with_time(Duration::from_secs(conf.general.tcp_keepalives_idle)), ) { Ok(_) => (), - Err(err) => error!("Could not configure socket: {}", err), + Err(err) => error!("Could not configure tcp_keepalive for socket: {}", err), } } Err(err) => error!("Could not configure socket: {}", err),