summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-06-08 13:49:29 +0100
committerGitHub <noreply@github.com>2021-06-08 13:49:29 +0100
commit1092718cac3800080bb766b251ae472282aef751 (patch)
tree1086a7a7407093fee8d9d470dd9b37e2fff3f7ea /synapse/storage
parentCorrect type hints for parse_string(s)_from_args. (#10137) (diff)
downloadsynapse-1092718cac3800080bb766b251ae472282aef751.tar.xz
Fix logging context when opening new DB connection (#10141)
Fixes #10140
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/database.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/synapse/storage/database.py b/synapse/storage/database.py
index b77368a460..d470cdacde 100644
--- a/synapse/storage/database.py
+++ b/synapse/storage/database.py
@@ -91,12 +91,18 @@ def make_pool(
     db_args = dict(db_config.config.get("args", {}))
     db_args.setdefault("cp_reconnect", True)
 
+    def _on_new_connection(conn):
+        # Ensure we have a logging context so we can correctly track queries,
+        # etc.
+        with LoggingContext("db.on_new_connection"):
+            engine.on_new_connection(
+                LoggingDatabaseConnection(conn, engine, "on_new_connection")
+            )
+
     return adbapi.ConnectionPool(
         db_config.config["name"],
         cp_reactor=reactor,
-        cp_openfun=lambda conn: engine.on_new_connection(
-            LoggingDatabaseConnection(conn, engine, "on_new_connection")
-        ),
+        cp_openfun=_on_new_connection,
         **db_args,
     )