summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2020-10-20 15:10:57 +0100
committerAndrew Morgan <andrew@amorgan.xyz>2020-10-20 15:10:57 +0100
commitac743d67f270227a0cdaf95b681ccd1ae22b5c78 (patch)
treed0679c6e6ae6ad3f3bf6823246bc2de93058abd0
parentMerge commit 'c9c544cda' into anoa/dinsic_release_1_21_x (diff)
parentClose the database connection we create during startup (#8131) (diff)
downloadsynapse-ac743d67f270227a0cdaf95b681ccd1ae22b5c78.tar.xz
Merge commit '12aebdfa5' into anoa/dinsic_release_1_21_x
* commit '12aebdfa5':
  Close the database connection we create during startup (#8131)
-rw-r--r--changelog.d/8131.bugfix1
-rw-r--r--synapse/storage/databases/__init__.py11
2 files changed, 11 insertions, 1 deletions
diff --git a/changelog.d/8131.bugfix b/changelog.d/8131.bugfix
new file mode 100644

index 0000000000..5110f235d1 --- /dev/null +++ b/changelog.d/8131.bugfix
@@ -0,0 +1 @@ +Fix a bug which could cause a leaked postgres connection if synapse was set to daemonize. 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.