From c18bc5c46955491e34d72a9e93e2d91a63b7822c Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Tue, 15 Aug 2023 16:53:08 -0700 Subject: [PATCH] use `session` rather than `local` for statement_timeout --- synapse/storage/background_updates.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/synapse/storage/background_updates.py b/synapse/storage/background_updates.py index eea0d1c8fbcc..9d598e584c95 100644 --- a/synapse/storage/background_updates.py +++ b/synapse/storage/background_updates.py @@ -238,6 +238,7 @@ class BackgroundUpdater: def __init__(self, hs: "HomeServer", database: "DatabasePool"): self._clock = hs.get_clock() self.db_pool = database + self.hs = hs self._database_name = database.name() @@ -760,7 +761,7 @@ def create_index_psql(conn: Connection) -> None: # override the global statement timeout to avoid accidentally squashing # a long-running index creation process - timeout_sql = "SET LOCAL statement_timeout = 0" + timeout_sql = "SET SESSION statement_timeout = 0" c.execute(timeout_sql) sql = ( @@ -777,6 +778,11 @@ def create_index_psql(conn: Connection) -> None: logger.debug("[SQL] %s", sql) c.execute(sql) + # mypy ignore - `statement_timeout` is defined on PostgresEngine + default_timeout = self.db_pool.engine.statement_timeout # type: ignore[attr-defined] + undo_timeout_sql = f"SET statement_timeout = {default_timeout}" + c.execute(undo_timeout_sql) + if replaces_index is not None: # We drop the old index as the new index has now been created. sql = f"DROP INDEX IF EXISTS {replaces_index}"