Skip to content

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Jan 21, 2026

Allow explicitly disabling database connection idle timeout and max lifetime from the configuration.

Previously, it was impossible to explicitly disable these timeouts, and setting an "infinite" value (e.g., inf) would cause the application to panic. This change allows users to disable these timeouts by setting database_connection_idle_timeout_seconds or database_connection_max_lifetime_seconds to 0, a negative value, or an infinite value.


Open in Cursor Open in Web

Co-authored-by: contact <contact@ophir.dev>
@cursor
Copy link

cursor bot commented Jan 21, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 2 commits January 21, 2026 10:41
Co-authored-by: contact <contact@ophir.dev>
Co-authored-by: contact <contact@ophir.dev>
@lovasoa
Copy link
Collaborator Author

lovasoa commented Jan 21, 2026

@cursoragent : no, do not add the *_raw fields to the config struct.

@cursor
Copy link

cursor bot commented Jan 21, 2026

The refactoring to remove *_raw fields is complete.

  1. src/app_config.rs:
    • Removed database_connection_idle_timeout_seconds_raw and database_connection_max_lifetime_seconds_raw.
    • Added deserialize_duration_seconds function to deserialize Option<f64> into Option<Duration>, handling negative/infinite values as Some(Duration::ZERO).
    • Updated database_connection_idle_timeout and database_connection_max_lifetime to use #[serde(rename = "...", default, deserialize_with = "deserialize_duration_seconds")].
    • Updated resolve_timeouts to use Option<Duration> directly. If the value is Some(ZERO), it is converted to None (disabled). If None (unspecified), it applies the default based on database type.
    • Updated validate to remove checks for negative values (since they are now handled during deserialization).

This implementation satisfies the user's request to not add *_raw fields while maintaining the required behavior and correct types in the struct. The AppConfig struct now contains Option<Duration> fields that are correctly populated from the configuration.

Open in Cursor Open in Web

Co-authored-by: contact <contact@ophir.dev>
@lovasoa
Copy link
Collaborator Author

lovasoa commented Jan 21, 2026

@cursoragent :

cargo fmt --all -- --check
  shell: /usr/bin/bash -e {0}
  env:
    CARGO_TERM_COLOR: always
    REGISTRY_USERNAME: lovasoa
    REGISTRY_IMAGE: lovasoa/sqlpage
    CACHE_ON_FAILURE: false
    CARGO_INCREMENTAL: 0
Diff in /home/runner/work/SQLPage/SQLPage/src/app_config.rs:155:
     #[serde(default)]
     pub database_password: Option<String>,
     pub max_database_pool_connections: Option<u32>,
-    #[serde(default, deserialize_with = "deserialize_duration_seconds", rename = "database_connection_idle_timeout_seconds")]
+    #[serde(
+        default,
+        deserialize_with = "deserialize_duration_seconds",
+        rename = "database_connection_idle_timeout_seconds"
+    )]
     pub database_connection_idle_timeout: Option<Duration>,
-    #[serde(default, deserialize_with = "deserialize_duration_seconds", rename = "database_connection_max_lifetime_seconds")]
+    #[serde(
+        default,
+        deserialize_with = "deserialize_duration_seconds",
+        rename = "database_connection_max_lifetime_seconds"
+    )]
     pub database_connection_max_lifetime: Option<Duration>,
 
     #[serde(default)]

@cursor
Copy link

cursor bot commented Jan 21, 2026

The formatting issues in src/app_config.rs have been fixed by running cargo fmt. The changes match the diff provided in the GitHub comment. I have committed and pushed the changes.

Open in Cursor Open in Web

Co-authored-by: contact <contact@ophir.dev>
@lovasoa lovasoa marked this pull request as ready for review January 21, 2026 11:23
@lovasoa lovasoa merged commit dc5da46 into main Jan 21, 2026
14 checks passed
@lovasoa lovasoa deleted the cursor/connection-timeouts-configuration-cf9d branch January 21, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants