From e117345e56c39053a06b132d8c05cf435f46389c Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 5 Nov 2026 10:50:58 +0300 Subject: [PATCH] fix(webvirtcloud): a PostgreSQL connection waits at most 5 seconds libpq connects without a timeout of its own: a database server that does not answer held each request for the operating system's TCP timeout, minutes. The settings template sets connect_timeout to 5 seconds. --- webvirtcloud/settings.py.template | 2 ++ webvirtcloud/tests/test_settings_env.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index d5fe1da7..0365fe0e 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -149,6 +149,8 @@ if db_host := os.getenv("WEBVIRTCLOUD_DB_HOST"): "NAME": os.getenv("WEBVIRTCLOUD_DB_NAME", "webvirtcloud"), "USER": os.getenv("WEBVIRTCLOUD_DB_USER", "webvirtcloud"), "PASSWORD": os.getenv("WEBVIRTCLOUD_DB_PASSWORD", ""), + # seconds to connect: libpq waits for the operating system's TCP timeout (minutes) + "OPTIONS": {"connect_timeout": 5}, } } else: diff --git a/webvirtcloud/tests/test_settings_env.py b/webvirtcloud/tests/test_settings_env.py index 571a94de..76a74409 100644 --- a/webvirtcloud/tests/test_settings_env.py +++ b/webvirtcloud/tests/test_settings_env.py @@ -122,6 +122,9 @@ class DatabaseEnvTestCase(SimpleTestCase): "NAME": "wvc", "USER": "wvcuser", "PASSWORD": "secret"}, ) + def test_postgres_connects_within_a_bounded_time(self): + self.assertEqual(self.db({"WEBVIRTCLOUD_DB_HOST": "db.example.com"})["OPTIONS"], {"connect_timeout": 5}) + def test_postgres_defaults(self): db = self.db({"WEBVIRTCLOUD_DB_HOST": "db.example.com"}) self.assertEqual(