1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-08 19:26:48 +00:00

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.
This commit is contained in:
catborise 2026-11-05 10:50:58 +03:00
parent 245ed12aad
commit e117345e56
2 changed files with 5 additions and 0 deletions

View file

@ -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:

View file

@ -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(