From 40ff87574b62c4541fe944e77ce1792e1a2cc4a7 Mon Sep 17 00:00:00 2001 From: Loren Yu Date: Tue, 8 Aug 2023 08:33:33 -0700 Subject: [PATCH] Increase Postgres connection timeout to 10 seconds (#182) ## Changes - Increase Postgres connection timeout to 10 seconds - Remove QueuePool timeout ## Context Database migrations are occasionally timing out in the platform-test-flask repo. Tuning this up to 10 seconds to see if that helps. Also removing the QueuePool timeout which doesn't seem needed. --- app/src/adapters/db/clients/postgres_client.py | 4 ++-- app/tests/src/adapters/db/clients/test_postgres_client.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/adapters/db/clients/postgres_client.py b/app/src/adapters/db/clients/postgres_client.py index 907946a..0e1217a 100644 --- a/app/src/adapters/db/clients/postgres_client.py +++ b/app/src/adapters/db/clients/postgres_client.py @@ -37,7 +37,7 @@ def _configure_engine(self, db_config: PostgresDBConfig) -> sqlalchemy.engine.En def get_conn() -> Any: return psycopg2.connect(**get_connection_parameters(db_config)) - conn_pool = pool.QueuePool(get_conn, max_overflow=10, pool_size=20, timeout=3) + conn_pool = pool.QueuePool(get_conn, max_overflow=10, pool_size=20) # The URL only needs to specify the dialect, since the connection pool # handles the actual connections. @@ -98,7 +98,7 @@ def get_connection_parameters(db_config: PostgresDBConfig) -> dict[str, Any]: password=password, port=db_config.port, options=f"-c search_path={db_config.db_schema}", - connect_timeout=3, + connect_timeout=10, sslmode=db_config.ssl_mode, **connect_args, ) diff --git a/app/tests/src/adapters/db/clients/test_postgres_client.py b/app/tests/src/adapters/db/clients/test_postgres_client.py index fc03e76..4af0863 100644 --- a/app/tests/src/adapters/db/clients/test_postgres_client.py +++ b/app/tests/src/adapters/db/clients/test_postgres_client.py @@ -50,6 +50,6 @@ def test_get_connection_parameters(monkeypatch: pytest.MonkeyPatch): password=db_config.password, port=db_config.port, options=f"-c search_path={db_config.db_schema}", - connect_timeout=3, + connect_timeout=10, sslmode="require", )