From ddeaca270fb44444e39cc93b36e7f20c50f69da0 Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 11:23:15 -0500 Subject: [PATCH 1/6] Add support for tcp_user_timeout --- src/messages.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/messages.rs b/src/messages.rs index ee4886df..9d950ab4 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -660,6 +660,8 @@ pub fn configure_socket(stream: &TcpStream) { match sock_ref.set_keepalive(true) { Ok(_) => { + #[cfg(target_os = "linux")] + sock_ref.set_tcp_user_timeout(10).unwrap(); match sock_ref.set_tcp_keepalive( &TcpKeepalive::new() .with_interval(Duration::from_secs(conf.general.tcp_keepalives_interval)) From fab0375d09bf9cac458cc8f6ba6618ceacd762fe Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 11:27:10 -0500 Subject: [PATCH 2/6] option --- src/messages.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/messages.rs b/src/messages.rs index 9d950ab4..79b58955 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -661,7 +661,7 @@ pub fn configure_socket(stream: &TcpStream) { match sock_ref.set_keepalive(true) { Ok(_) => { #[cfg(target_os = "linux")] - sock_ref.set_tcp_user_timeout(10).unwrap(); + sock_ref.set_tcp_user_timeout(Some(10)).unwrap(); match sock_ref.set_tcp_keepalive( &TcpKeepalive::new() .with_interval(Duration::from_secs(conf.general.tcp_keepalives_interval)) From 1852009316bf08bdddea690d0012b6af4dd0dd1e Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 11:54:08 -0500 Subject: [PATCH 3/6] duration --- src/messages.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/messages.rs b/src/messages.rs index 79b58955..d0c192dc 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -661,7 +661,11 @@ pub fn configure_socket(stream: &TcpStream) { match sock_ref.set_keepalive(true) { Ok(_) => { #[cfg(target_os = "linux")] - sock_ref.set_tcp_user_timeout(Some(10)).unwrap(); + match sock_ref.set_tcp_user_timeout(Duration::from_millis(1000)) { + Ok(_) => (), + Err(err) => error!("Could not configure tcp_user_timeout for socket: {}", err), + } + match sock_ref.set_tcp_keepalive( &TcpKeepalive::new() .with_interval(Duration::from_secs(conf.general.tcp_keepalives_interval)) @@ -669,7 +673,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), From 1bcfcf93fc65ae7ffe03706bd30122084320b842 Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 11:59:56 -0500 Subject: [PATCH 4/6] Some() --- src/messages.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/messages.rs b/src/messages.rs index d0c192dc..3b7796e8 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -658,14 +658,14 @@ 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(1000))) { + Ok(_) => (), + Err(err) => error!("Could not configure tcp_user_timeout for socket: {}", err), + } + match sock_ref.set_keepalive(true) { Ok(_) => { - #[cfg(target_os = "linux")] - match sock_ref.set_tcp_user_timeout(Duration::from_millis(1000)) { - Ok(_) => (), - Err(err) => error!("Could not configure tcp_user_timeout for socket: {}", err), - } - match sock_ref.set_tcp_keepalive( &TcpKeepalive::new() .with_interval(Duration::from_secs(conf.general.tcp_keepalives_interval)) From b84719d253d16c058e26ae0c5ee7538c4bb1c0d6 Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 12:41:36 -0500 Subject: [PATCH 5/6] docs --- CONFIG.md | 10 ++++++++-- src/config.rs | 6 ++++++ src/messages.rs | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index b36a190d..e4577c3c 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -1,4 +1,4 @@ -# PgCat Configurations +# PgCat Configurations ## `general` Section ### host @@ -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 2f5596c6..c170b9af 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, @@ -351,6 +353,10 @@ impl General { 5 // 5 seconds } + pub fn default_tcp_user_timeout() -> u64 { + 10000 // 10000 milliseconds + } + pub fn default_idle_timeout() -> u64 { 60000 // 10 minutes } diff --git a/src/messages.rs b/src/messages.rs index 3b7796e8..8767776b 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -659,7 +659,7 @@ pub fn configure_socket(stream: &TcpStream) { let conf = get_config(); #[cfg(target_os = "linux")] - match sock_ref.set_tcp_user_timeout(Some(Duration::from_millis(1000))) { + 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), } From 5a474019e7fc5db690a24516ee3098fb35ead490 Mon Sep 17 00:00:00 2001 From: Mostafa Abdelraouf Date: Wed, 12 Jul 2023 13:00:28 -0500 Subject: [PATCH 6/6] fmt, compile --- src/config.rs | 1 + src/messages.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index c170b9af..612e2168 100644 --- a/src/config.rs +++ b/src/config.rs @@ -416,6 +416,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 8767776b..d2ccf8a7 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -659,7 +659,8 @@ pub fn configure_socket(stream: &TcpStream) { let conf = get_config(); #[cfg(target_os = "linux")] - match sock_ref.set_tcp_user_timeout(Some(Duration::from_millis(conf.general.tcp_user_timeout))) { + 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), }