Skip to content

config/database_pools: Change tcp_timeout field to Duration #11184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/config/database_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct DbPoolConfig {
/// packet loss between the application and the database: setting it too high will result in an
/// unnecessarily long outage (before the unhealthy database logic kicks in), while setting it
/// too low might result in healthy connections being dropped.
pub tcp_timeout_ms: u64,
pub tcp_timeout: Duration,
/// Time to wait for a connection to become available from the connection
/// pool before returning an error.
pub connection_timeout: Duration,
Expand Down Expand Up @@ -78,7 +78,8 @@ impl DatabasePools {
let primary_min_idle = var_parsed("DB_PRIMARY_MIN_IDLE")?;
let replica_min_idle = var_parsed("DB_REPLICA_MIN_IDLE")?;

let tcp_timeout_ms = var_parsed("DB_TCP_TIMEOUT_MS")?.unwrap_or(15 * 1000);
let tcp_timeout = var_parsed("DB_TCP_TIMEOUT_MS")?.unwrap_or(15 * 1000);
let tcp_timeout = Duration::from_millis(tcp_timeout);

let connection_timeout = var_parsed("DB_TIMEOUT")?.unwrap_or(30);
let connection_timeout = Duration::from_secs(connection_timeout);
Expand All @@ -102,7 +103,7 @@ impl DatabasePools {
read_only_mode: true,
pool_size: primary_async_pool_size,
min_idle: primary_min_idle,
tcp_timeout_ms,
tcp_timeout,
connection_timeout,
statement_timeout,
helper_threads,
Expand All @@ -117,7 +118,7 @@ impl DatabasePools {
read_only_mode,
pool_size: primary_async_pool_size,
min_idle: primary_min_idle,
tcp_timeout_ms,
tcp_timeout,
connection_timeout,
statement_timeout,
helper_threads,
Expand All @@ -131,7 +132,7 @@ impl DatabasePools {
read_only_mode,
pool_size: primary_async_pool_size,
min_idle: primary_min_idle,
tcp_timeout_ms,
tcp_timeout,
connection_timeout,
statement_timeout,
helper_threads,
Expand All @@ -145,7 +146,7 @@ impl DatabasePools {
read_only_mode: true,
pool_size: replica_async_pool_size,
min_idle: replica_min_idle,
tcp_timeout_ms,
tcp_timeout,
connection_timeout,
statement_timeout,
helper_threads,
Expand Down
2 changes: 1 addition & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn connection_url(config: &config::DbPoolConfig) -> String {
maybe_append_url_param(
&mut url,
"tcp_user_timeout",
&config.tcp_timeout_ms.to_string(),
&config.tcp_timeout.as_millis().to_string(),
);

url.into()
Expand Down
4 changes: 2 additions & 2 deletions src/tests/util/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl TestAppBuilder {
read_only_mode: true,
pool_size: primary.pool_size,
min_idle: primary.min_idle,
tcp_timeout_ms: primary.tcp_timeout_ms,
tcp_timeout: primary.tcp_timeout,
connection_timeout: primary.connection_timeout,
statement_timeout: primary.statement_timeout,
helper_threads: primary.helper_threads,
Expand All @@ -424,7 +424,7 @@ fn simple_config() -> config::Server {
read_only_mode: false,
pool_size: 5,
min_idle: None,
tcp_timeout_ms: 1000, // 1 second
tcp_timeout: Duration::from_secs(1),
connection_timeout: Duration::from_secs(1),
statement_timeout: Duration::from_secs(1),
helper_threads: 1,
Expand Down