Skip to content

Commit 70d28df

Browse files
authored
config/database_pools: Change tcp_timeout field to Duration (#11184)
1 parent f4dd974 commit 70d28df

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/config/database_pools.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct DbPoolConfig {
3737
/// packet loss between the application and the database: setting it too high will result in an
3838
/// unnecessarily long outage (before the unhealthy database logic kicks in), while setting it
3939
/// too low might result in healthy connections being dropped.
40-
pub tcp_timeout_ms: u64,
40+
pub tcp_timeout: Duration,
4141
/// Time to wait for a connection to become available from the connection
4242
/// pool before returning an error.
4343
pub connection_timeout: Duration,
@@ -78,7 +78,8 @@ impl DatabasePools {
7878
let primary_min_idle = var_parsed("DB_PRIMARY_MIN_IDLE")?;
7979
let replica_min_idle = var_parsed("DB_REPLICA_MIN_IDLE")?;
8080

81-
let tcp_timeout_ms = var_parsed("DB_TCP_TIMEOUT_MS")?.unwrap_or(15 * 1000);
81+
let tcp_timeout = var_parsed("DB_TCP_TIMEOUT_MS")?.unwrap_or(15 * 1000);
82+
let tcp_timeout = Duration::from_millis(tcp_timeout);
8283

8384
let connection_timeout = var_parsed("DB_TIMEOUT")?.unwrap_or(30);
8485
let connection_timeout = Duration::from_secs(connection_timeout);
@@ -102,7 +103,7 @@ impl DatabasePools {
102103
read_only_mode: true,
103104
pool_size: primary_async_pool_size,
104105
min_idle: primary_min_idle,
105-
tcp_timeout_ms,
106+
tcp_timeout,
106107
connection_timeout,
107108
statement_timeout,
108109
helper_threads,
@@ -117,7 +118,7 @@ impl DatabasePools {
117118
read_only_mode,
118119
pool_size: primary_async_pool_size,
119120
min_idle: primary_min_idle,
120-
tcp_timeout_ms,
121+
tcp_timeout,
121122
connection_timeout,
122123
statement_timeout,
123124
helper_threads,
@@ -131,7 +132,7 @@ impl DatabasePools {
131132
read_only_mode,
132133
pool_size: primary_async_pool_size,
133134
min_idle: primary_min_idle,
134-
tcp_timeout_ms,
135+
tcp_timeout,
135136
connection_timeout,
136137
statement_timeout,
137138
helper_threads,
@@ -145,7 +146,7 @@ impl DatabasePools {
145146
read_only_mode: true,
146147
pool_size: replica_async_pool_size,
147148
min_idle: replica_min_idle,
148-
tcp_timeout_ms,
149+
tcp_timeout,
149150
connection_timeout,
150151
statement_timeout,
151152
helper_threads,

src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn connection_url(config: &config::DbPoolConfig) -> String {
3535
maybe_append_url_param(
3636
&mut url,
3737
"tcp_user_timeout",
38-
&config.tcp_timeout_ms.to_string(),
38+
&config.tcp_timeout.as_millis().to_string(),
3939
);
4040

4141
url.into()

src/tests/util/test_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl TestAppBuilder {
401401
read_only_mode: true,
402402
pool_size: primary.pool_size,
403403
min_idle: primary.min_idle,
404-
tcp_timeout_ms: primary.tcp_timeout_ms,
404+
tcp_timeout: primary.tcp_timeout,
405405
connection_timeout: primary.connection_timeout,
406406
statement_timeout: primary.statement_timeout,
407407
helper_threads: primary.helper_threads,
@@ -424,7 +424,7 @@ fn simple_config() -> config::Server {
424424
read_only_mode: false,
425425
pool_size: 5,
426426
min_idle: None,
427-
tcp_timeout_ms: 1000, // 1 second
427+
tcp_timeout: Duration::from_secs(1),
428428
connection_timeout: Duration::from_secs(1),
429429
statement_timeout: Duration::from_secs(1),
430430
helper_threads: 1,

0 commit comments

Comments
 (0)