From 8200d1953c00656308551e6e4b1f8c2a866a005b Mon Sep 17 00:00:00 2001 From: Yago Iglesias Date: Fri, 1 Sep 2023 21:31:35 +0200 Subject: [PATCH] feat: Set timeout to 2 secs --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index c548ef2..6237f16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use secrecy::ExposeSecret; -use sqlx::PgPool; +use sqlx::postgres::PgPoolOptions; use std::net::TcpListener; use tracing::subscriber::set_global_default; use tracing_log::LogTracer; @@ -16,13 +16,15 @@ async fn main() -> Result<(), std::io::Error> { // We want to panic if we cannot read the configuration let configuration = get_configuration().expect("Failed to read configurations"); - let connection = PgPool::connect_lazy( - configuration - .database - .get_connnection_string() - .expose_secret(), - ) - .expect("Failed to connect to Postgres"); + let connection = PgPoolOptions::new() + .acquire_timeout(std::time::Duration::from_secs(2)) + .connect_lazy( + configuration + .database + .get_connnection_string() + .expose_secret(), + ) + .expect("Failed to connect to Postgres"); // Bind the TCP listener socket address with the configuration port let address = format!(