summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-08-19 20:41:53 +0100
committerGitHub <noreply@github.com>2020-08-19 20:41:53 +0100
commit12aebdfa5a81abaf4b7864c561e23c4a5b4945ca (patch)
tree55c7b544c2a17f30063e28d9e2ba2fa97ce5dc28 /synapse/storage/databases
parentRemove `ChainedIdGenerator`. (#8123) (diff)
downloadsynapse-12aebdfa5a81abaf4b7864c561e23c4a5b4945ca.tar.xz
Close the database connection we create during startup (#8131)
... otherwise it gets leaked.
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/__init__.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/storage/databases/__init__.py b/synapse/storage/databases/__init__.py
index 4406e58273..0ac854aee2 100644
--- a/synapse/storage/databases/__init__.py
+++ b/synapse/storage/databases/__init__.py
@@ -87,12 +87,21 @@ class Databases(object):
 
                 logger.info("Database %r prepared", db_name)
 
+            # Closing the context manager doesn't close the connection.
+            # psycopg will close the connection when the object gets GCed, but *only*
+            # if the PID is the same as when the connection was opened [1], and
+            # it may not be if we fork in the meantime.
+            #
+            # [1]: https://github.com/psycopg/psycopg2/blob/2_8_5/psycopg/connection_type.c#L1378
+
+            db_conn.close()
+
         # Sanity check that we have actually configured all the required stores.
         if not main:
             raise Exception("No 'main' data store configured")
 
         if not state:
-            raise Exception("No 'main' data store configured")
+            raise Exception("No 'state' data store configured")
 
         # We use local variables here to ensure that the databases do not have
         # optional types.