Skip to content

Optionally validate config on boot #423

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 4, 2023
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
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ pub struct General {
pub admin_username: String,
pub admin_password: String,

#[serde(default = "General::default_validate_config")]
pub validate_config: bool,

// Support for auth query
pub auth_query: Option<String>,
pub auth_query_user: Option<String>,
Expand Down Expand Up @@ -367,6 +370,10 @@ impl General {
pub fn default_idle_client_in_transaction_timeout() -> u64 {
0
}

pub fn default_validate_config() -> bool {
true
}
}

impl Default for General {
Expand Down Expand Up @@ -402,6 +409,7 @@ impl Default for General {
auth_query_user: None,
auth_query_password: None,
server_lifetime: 1000 * 3600 * 24, // 24 hours,
validate_config: true,
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,12 @@ impl ConnectionPool {
// Connect to the servers to make sure pool configuration is valid
// before setting it globally.
// Do this async and somewhere else, we don't have to wait here.
let mut validate_pool = pool.clone();
tokio::task::spawn(async move {
let _ = validate_pool.validate().await;
});
if config.general.validate_config {
let mut validate_pool = pool.clone();
tokio::task::spawn(async move {
let _ = validate_pool.validate().await;
});
}

// There is one pool per database/user pair.
new_pools.insert(PoolIdentifier::new(pool_name, &user.username), pool);
Expand Down