Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Close the database connection we create during startup #8131

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8131.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which could cause a leaked postgres connection if synapse was set to daemonize.
11 changes: 10 additions & 1 deletion synapse/storage/databases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,21 @@ def __init__(self, main_store_class, hs):

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.
Expand Down